Figures & Margin Content

When using msmbstyle you can make use of all the plot configuration settings that are provided by bookdown and tufte, including references, figure captions, and margin figures.

The examples shown below are taken directly from the tufte vignette (https://rstudio.github.io/tufte/) to demonstrate how they are styled by msmbstyle.

Margin Figures

Images and graphics play an integral role in Tufte's work. To place figures in the margin you can use the knitr chunk option fig.margin = TRUE. For example:

library(ggplot2)
mtcars2 <- mtcars
mtcars2$am <- factor(
  mtcars$am, labels = c('automatic', 'manual')
)
ggplot(mtcars2, aes(hp, mpg, color = am)) +
  geom_point() + geom_smooth() +
  theme(legend.position = 'bottom')

Note the use of the fig.cap chunk option to provide a figure caption. You can adjust the proportions of figures using the fig.width and fig.height chunk options. These are specified in inches, and will be automatically scaled down to fit within the handout margin.

Arbitrary Margin Content

In fact, you can include anything in the margin using the knitr engine named marginfigure. Unlike R code chunks ```r, you write a chunk starting with ```{marginfigure} instead, then put the content in the chunk. See an example on the right about the first fundamental theorem of calculus.

We know from _the first fundamental theorem of calculus_ that for $x$ in $[a, b]$:
$$\frac{d}{dx}\left( \int_{a}^{x} f(u)\,du\right)=f(x).$$

For the sake of portability between LaTeX and HTML, you should keep the margin content as simple as possible (syntax-wise) in the marginfigure blocks. You may use simple Markdown syntax like **bold** and _italic_ text, but please refrain from using footnotes, citations, or block-level elements (e.g. blockquotes and lists) there.

Full Width Figures

You can arrange for figures to span across the entire page by using the chunk option fig.fullwidth = TRUE.

ggplot(diamonds, aes(carat, price)) + geom_smooth() +
  facet_grid(~ cut)

Other chunk options related to figures can still be used, such as fig.width, fig.cap, out.width, and so on. For full width figures, usually fig.width is large and fig.height is small. In the above example, the plot size is $10 \times 2$.

Main Column Figures

Besides margin and full width figures, you can of course also include figures constrained to the main column. This is the default type of figures in the LaTeX/HTML output.

ggplot(diamonds, aes(cut, price)) + geom_boxplot()


grimbough/msmbstyle documentation built on April 9, 2022, 5:09 p.m.