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):
Get Dynamic Documents with R and knitr, 2nd Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.