6.2 Figures

6.2.1 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:

```{r fig-margin, fig.margin=TRUE}

As in other Rmd documents, you can use the fig.cap chunk option to provide a figure caption, and adjust figure sizes using the fig.width and fig.height chunk options, which are specified in inches, and will be automatically scaled down to fit within the handout margin.

Figure 6.2 shows what a margin figure looks like.

A margin figure in the Tufte style.

FIGURE 6.2: A margin figure in the Tufte style.

6.2.2 Arbitrary margin content

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, e.g.,

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.

Note that if you set echo = FALSE in your global chunk options, you will have to add echo = TRUE to the chunk to display a margin figure, for example ```{marginfigure, echo = TRUE}.

6.2.3 Full-width figures

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

```{r, fig.width=10, fig.height=2, fig.fullwidth=TRUE}
par(mar = c(4, 4, .1, .2)); plot(sunspots)

Other chunk options related to figures can still be used, such as fig.width, fig.cap, and out.width, etc. For full-width figures, usually fig.width is large and fig.height is small. In the above example, the plot size is 10x2.

Figure 6.3 shows what a full-width figure looks like.

A full-width figure in the Tufte style.

FIGURE 6.3: A full-width figure in the Tufte style.

6.2.4 Main column figures

Besides margin and full-width figures, you can certainly also include figures constrained to the main column. This is the default type of figures in the LaTeX/HTML output, and requires no special chunk options.

Figure 6.4 shows what a figure looks like in the main column.

A figure in the main column in the Tufte style.

FIGURE 6.4: A figure in the main column in the Tufte style.