+ - 0:00:00
Notes for current slide
Notes for next slide

Essentials 07: Exporting Plots

1 / 7

Setup

Tasks:

  1. Open the slides for today

  2. Open/create your seminRs project

  3. Download the R Script to your seminRs project

2 / 7

Exporting Plots with ggsave()

Usage

ggsave("peng_scatterplot.png", plot = peng_scatter) # to use the default size
# or
ggsave("peng_scatter_2.png", plot = peng_scatter, width = 15, height = 15, units = "cm")

Where "peng_scatterplot.png" is the name we want to give the new file & the image type we want it to be

  • we can create many different file types (pdf, jpeg & so on..)

plot = peng_scatter is the name of the plot object that we've created with ggplot()

width = & height = allows us to specify the size of the image, measured in the units = we've specified

The plot will be saved to your working directory (aka your R project) by default, or you can specify a file path

3 / 7

Assignment <-

To be able to specify the plot object we want to save with ggsave(), we have to give our plot a name <-

For example:

peng_scatter <- ggplot2::ggplot(peng_data, aes(bill_length_mm, bill_depth_mm, colour = species))
peng_scatter <- peng_scatter +
geom_point() +
labs(title = "Scatterplot of Bill Length & Bill Depth",
x = "Bill Length (mm)", y = "Bill Depth (mm)") +
theme_bw()

If you save your plot, and can't see any data points on it - just the grid, it is likely you have skipped out this assignment step

Just assign your plot like above, re-run the code, & re-run ggsave() to overwrite the image

4 / 7

Inserting into Word

Inserting your exported plots into a Word doc is super simple

Insert > Pictures > This Device.. & select the image from your working directory


5 / 7

Your Turn! 🥳

Practise using ggsave() with the examples in the R Script


Try using ggsave() to save your plot for the AnD assignment and insert it into your Word doc (make sure to switch to your report project)

6 / 7

Made with Padlet
7 / 7

Setup

Tasks:

  1. Open the slides for today

  2. Open/create your seminRs project

  3. Download the R Script to your seminRs project

2 / 7
Paused

Help

Keyboard shortcuts

, , Pg Up, k Go to previous slide
, , Pg Dn, Space, j Go to next slide
Home Go to first slide
End Go to last slide
Number + Return Go to specific slide
b / m / f Toggle blackout / mirrored / fullscreen mode
c Clone slideshow
p Toggle presenter mode
t Restart the presentation timer
?, h Toggle this help
Esc Back to slideshow