Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Learn Sharing and Exporting Visualizations | Reporting and Communicating Insights
Visualization and Reporting with R

bookSharing and Exporting Visualizations

Sharing your visualizations and results is a critical part of communicating insights in data analysis. Exporting plots and tables allows you to include them in reports, presentations, or send them to collaborators who may not have access to your R environment. By mastering export techniques, you ensure your work is accessible, reproducible, and impactful beyond your own workspace.

1234567891011
library(ggplot2) # Create a simple plot p <- ggplot(mtcars, aes(x = wt, y = mpg)) + geom_point() # Save the plot as a PNG image ggsave("my_plot.png", plot = p, width = 6, height = 4, dpi = 300) # Save the plot as a PDF ggsave("my_plot.pdf", plot = p, width = 6, height = 4)
copy

When sharing visualizations, the file format you choose can affect how your audience views and uses the plot. Use PNG or JPEG formats for images that will be embedded in presentations or viewed on the web, as these are widely supported and easy to share. PDF and SVG formats are best when you need high-quality, scalable graphics for print or further editing. Choose the format that matches your audience's needs and the context in which your visualization will be used.

# Export a data frame to a CSV file
write.csv(mtcars, "mtcars_summary.csv", row.names = FALSE)

# Export to Excel (requires the writexl package)
# install.packages("writexl")
library(writexl)
write_xlsx(mtcars, "mtcars_summary.xlsx")

This code builds a time-series sales chart and highlights a key business event directly on the plot. A new event column is created using ifelse(), which assigns the label "Product Launch" only to the year 2020 and leaves other years empty. This allows the annotation to appear at a single, meaningful point without altering or filtering the dataset.

The plot is constructed with ggplot2 using layered geoms: geom_line() shows overall sales trends, geom_point() emphasizes individual yearly values, and geom_text() places the event label above the corresponding data point. Titles and axis labels add context, and print() ensures the plot is rendered. This pattern is commonly used to visually connect data trends with important real-world events in analytical reports.

1. Which function is used to save a ggplot2 plot as an image file?

2. Why is it important to choose the right file format when exporting visualizations?

question mark

Which function is used to save a ggplot2 plot as an image file?

Select the correct answer

question mark

Why is it important to choose the right file format when exporting visualizations?

Select the correct answer

Everything was clear?

How can we improve it?

Thanks for your feedback!

SectionΒ 3. ChapterΒ 5

Ask AI

expand

Ask AI

ChatGPT

Ask anything or try one of the suggested questions to begin our chat

bookSharing and Exporting Visualizations

Swipe to show menu

Sharing your visualizations and results is a critical part of communicating insights in data analysis. Exporting plots and tables allows you to include them in reports, presentations, or send them to collaborators who may not have access to your R environment. By mastering export techniques, you ensure your work is accessible, reproducible, and impactful beyond your own workspace.

1234567891011
library(ggplot2) # Create a simple plot p <- ggplot(mtcars, aes(x = wt, y = mpg)) + geom_point() # Save the plot as a PNG image ggsave("my_plot.png", plot = p, width = 6, height = 4, dpi = 300) # Save the plot as a PDF ggsave("my_plot.pdf", plot = p, width = 6, height = 4)
copy

When sharing visualizations, the file format you choose can affect how your audience views and uses the plot. Use PNG or JPEG formats for images that will be embedded in presentations or viewed on the web, as these are widely supported and easy to share. PDF and SVG formats are best when you need high-quality, scalable graphics for print or further editing. Choose the format that matches your audience's needs and the context in which your visualization will be used.

# Export a data frame to a CSV file
write.csv(mtcars, "mtcars_summary.csv", row.names = FALSE)

# Export to Excel (requires the writexl package)
# install.packages("writexl")
library(writexl)
write_xlsx(mtcars, "mtcars_summary.xlsx")

This code builds a time-series sales chart and highlights a key business event directly on the plot. A new event column is created using ifelse(), which assigns the label "Product Launch" only to the year 2020 and leaves other years empty. This allows the annotation to appear at a single, meaningful point without altering or filtering the dataset.

The plot is constructed with ggplot2 using layered geoms: geom_line() shows overall sales trends, geom_point() emphasizes individual yearly values, and geom_text() places the event label above the corresponding data point. Titles and axis labels add context, and print() ensures the plot is rendered. This pattern is commonly used to visually connect data trends with important real-world events in analytical reports.

1. Which function is used to save a ggplot2 plot as an image file?

2. Why is it important to choose the right file format when exporting visualizations?

question mark

Which function is used to save a ggplot2 plot as an image file?

Select the correct answer

question mark

Why is it important to choose the right file format when exporting visualizations?

Select the correct answer

Everything was clear?

How can we improve it?

Thanks for your feedback!

SectionΒ 3. ChapterΒ 5
some-alt