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 theknitr chunk optionfig.margin = TRUE. For example:

```{r fig-margin, fig.margin=TRUE}plot(cars)```

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

Figure6.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 theknitr engine namedmarginfigure. Unlike R code chunks```{r}, you write a chunk starting with```{marginfigure} instead, then put the content in the chunk, e.g.,

```{marginfigure}We know from _the first fundamental theorem of calculus_ thatfor $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 themarginfigure 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 setecho = FALSE in your global chunk options, you will have to addecho = 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 optionfig.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 asfig.width,fig.cap, andout.width, etc. For full-width figures, usuallyfig.width is large andfig.height is small. In the above example, the plot size is 10x2.

Figure6.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.

Figure6.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.