7

Graphics

Graphics are an important part of reports, and a lot of efforts have been made in knitr to make sure graphics output is natural and flexible. For example, knitr tries to mimic the behavior of the R console, and grid graphics (Murrell, 2011) may not need to be explicitly printed as long as the same code can produce plots in the R console (in some cases, however, they have to be printed, e.g., in a loop, because we have to do so in an R console); below is a chunk of code that will produce a plot in both the R console and knitr (see Figure 7.1):

Image

FIGURE 7.1: A plot created in ggplot2 that does not need to be printed explicitly (by comparison, ...

Get Dynamic Documents with R and knitr, 2nd Edition now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.