Useful tricks when including images in Rmarkdown documents

June 26, 2017

(This article was first published on Revolutions, and kindly contributed to R-bloggers)

Rmarkdown is an enormously useful system for combining text, output and graphics generated by R into a single document. Images, in particular, are a powerful means of communication in a report, whether they be data visualizations, diagrams, or pictures. To maximize the power of those images, Zev Ross has created a comprehensive list of tips and tricks for working with images in R markdown documents. Those tips include:

While Zev's guide focuses on manipulating images as generated by R, this might also be a good time to revisit these tips on making the graphics themselves as attractive and useful as possible. Although written many years ago, most of these tips are still relevant, in particular:

  • If you plan to print (or these days, view on high-resolution displays), use PDF output
  • Use PNG for R graphics output, and use a high-resolution if you plan to print. Don't ever use JPG for R graphics output.
  • Think about the aspect ratio of your graphics.
  • Remove unused whitespace around your graphics (more of an issue for base R grahics; ggplot2 handles this pretty well already).

You may also find the Rmarkdown cheat sheet helpful if you're working with Rmarkdown documents.

ZevRoss Technical Blog: Tips and tricks for working with images and figures in R Markdown documents

To leave a comment for the author, please follow the link and comment on their blog: Revolutions. offers daily e-mail updates about R news and tutorials on topics such as: Data science, Big Data, R jobs, visualization (ggplot2, Boxplots, maps, animation), programming (RStudio, Sweave, LaTeX, SQL, Eclipse, git, hadoop, Web Scraping) statistics (regression, PCA, time series, trading) and more...

If you got this far, why not subscribe for updates from the site? Choose your flavor: e-mail, twitter, RSS, or facebook...

Comments are closed.

Search R-bloggers


Never miss an update!
Subscribe to R-bloggers to receive
e-mails with the latest R posts.
(You will not see this message again.)

Click here to close (This popup will not appear again)