class: center, middle, inverse, title-slide # Essentials 07: Exporting Plots --- class: inverse # Setup ### .orange[Tasks]: 1. Open the slides for today 1. Open/create your seminRs project 1. Download the [R Script](https://and.netlify.app/seminr/07/essentials/essentials_07.R) to your seminRs project --- class: inverse # Exporting Plots with ggsave() ### Usage ```r 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 .orange["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..) .orange[plot = peng_scatter] is the name of the plot object that we've created with ggplot() .orange[width =] & .orange[height =] allows us to specify the size of the image, measured in the .orange[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 --- class: inverse # Assignment .orange[<-] To be able to specify the plot object we want to save with ggsave(), we have to give our plot a name .orange[<-] For example: ```r 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 --- class: inverse # Inserting into Word Inserting your exported plots into a Word doc is super simple .italic[Insert > Pictures > This Device..] & select the image from your working directory <br> .center[ <img src="./images/insrt.png" width="70%" /> ] --- class: inverse, center, middle # Your Turn! 🥳 Practise using ggsave() with the examples in the [R Script](https://and.netlify.app/seminr/07/essentials/essentials_07.R) <br> 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) --- class: center, middle <div class="padlet-embed" style="border:1px solid rgba(0,0,0,0.1);border-radius:2px;box-sizing:border-box;overflow:hidden;position:relative;width:100%;background:#F4F4F4"><p style="padding:0;margin:0"><iframe src="https://uofsussex.padlet.org/embed/nrud4gk8x63gbfdc" frameborder="0" allow="camera;microphone;geolocation" style="width:100%;height:608px;display:block;padding:0;margin:0"></iframe></p><div style="padding:8px;text-align:right;margin:0;"><a href="https://padlet.com?ref=embed" style="padding:0;margin:0;border:none;display:block;line-height:1;height:16px" target="_blank"><img src="https://padlet.net/embeds/made_with_padlet.png" width="86" height="16" style="padding:0;margin:0;background:none;border:none;display:inline;box-shadow:none" alt="Made with Padlet"></a></div></div>