Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Aprende Saving and Exporting Plots | section
Hands-On Data Visualization with ggplot2 in R

bookSaving and Exporting Plots

Desliza para mostrar el menú

When you create visualizations in R using ggplot2, you often need to share your work with others or include plots in reports and presentations. Exporting high-quality graphics is essential to ensure your visualizations remain clear, professional, and visually appealing in any medium. Low-resolution or poorly formatted images can make your insights difficult to interpret and reduce the impact of your data storytelling.

123456789101112
# Saving a ggplot as a PNG file with default settings library(ggplot2) p <- ggplot(mtcars, aes(x = wt, y = mpg)) + geom_point() # Save as PNG ggsave("scatterplot.png", plot = p) # Save as PDF with specific width and height (in inches) ggsave("scatterplot.pdf", plot = p, width = 8, height = 6) # Save as JPEG with higher resolution (dpi) ggsave("scatterplot_highres.jpg", plot = p, dpi = 300)
copy

When exporting and sharing your visualizations, consider the following best practices:

  • Choose a file format that fits your needs; use PNG or JPEG for presentations, and PDF or SVG for print or further editing;
  • Set the width, height, and resolution (dpi) to ensure your plot appears crisp in its final destination;
  • Use descriptive, consistent filenames to keep your files organized and easy to find;
  • Always check your exported plots for clarity, correct sizing, and formatting before sharing or embedding them in documents.
¿Todo estuvo claro?

¿Cómo podemos mejorarlo?

¡Gracias por tus comentarios!

Sección 1. Capítulo 12

Pregunte a AI

expand

Pregunte a AI

ChatGPT

Pregunte lo que quiera o pruebe una de las preguntas sugeridas para comenzar nuestra charla

Sección 1. Capítulo 12
some-alt