Exporting Plots: Saving High-Quality Graphics
You've crafted your viusalization — now what? Time to share it! This lesson covers how to export high-quality graphics from R for papers, slides, or social media.
Learn which formats to choose, how to control resolution, and what to watch out for when saving plots across platforms.
🎞️ From Plot to Image
Sharing your plots effectively means more than just exporting an image. Correctly handling dimensions, resolution, and format ensures that your graphics remain sharp, readable, and visually consistent — whether they appear in papers, presentations, or online.
In R with ggplot2, your workhorse is ggsave().
But exporting is usually more than ggsave("my_plot.png").
ggsave() does not only handle the name and format of the file (based on the extension, such as .png,.pdf, .svg), but lets you control the aspect ratio and resolution so the output looks crisp wherever it goes.
- Format — add a file extension to the name of your plot. Before choosing a specific file format, it helps to know the general distinction between raster and vector graphics:
- Raster files (like
png,jpg, andtif) are made of pixels, so enlarging them too much can make them blurry or blocky.
Pick raster for web and on-screen use with appropriate pixel dimensions, e.g. 1200×800 px. Use higher resolution (~300–600 dpi) when preparing files for print sharing via social media or messengers. - Vector files (like
pdfandsvg) store shapes and lines, so they can be scaled infinitely without losing sharpness.
Choose vector for print and post-editing in tools like Adobe Illustrator, Inkscape, or Figma. Avoid vector files when using very large datasets with millions of points (files can get heavy).
- Raster files (like
- Aspect ratio — control the aspect ratio by setting
widthandheight(using values with"in"or"cm"as units). If you increase the plot size, geometries and theme elements will appear smaller. - Resolution (DPI) — controls the pixel density of raster files. Does not apply to vector files, and is irrelevant for web graphics.
Ready to enroll? 🚀
Enroll now to unlock instant, lifetime access to every lesson, and become the ggplot2 expert your company needs!
Already enrolled? Login