Useful tricks when including images in Rmarkdown documents

[This article was first published on Revolutions, and kindly contributed to R-bloggers]. (You can report issue about the content on this page here)
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

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 about learning R and many other topics. Click here if you're looking to post or find an R/data-science job.
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

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)