class: center, middle, inverse, title-slide # Saving ### Gina Reynolds, July 2019 --- --- name: saving # The written language: Save plots as objects and to disk Now you should know how to build a ggplot. How can you save that plot? First, you can save the entire plot as an object using the assignment operator `<-`. Below we call the plot `g`. Then use the function ggsave() to save out your plot. ```r g <- ggplot(gapminder_2002) + aes(x = gdpPercap) + aes(y = lifeExp) + geom_point() ggsave(filename = "figures/my_plot0.png", plot = g, height = 5, width = 8) ``` --- class: split-40 count: false .left-panel-save-1[ ```r ggsave(filename = "figures/my_plot.png", plot = g, height = 6, width = 8) knitr::include_graphics(path = "figures/my_plot.png") ``` ] .right-panel-save-1[ <img src="figures/my_plot.png" width="100%" /> ] <style> .left-panel-save-1 { color: #777; width: 38.6138613861386%; height: 92%; float: left; font-size: 80% } .right-panel-save-1 { width: 59.4059405940594%; float: right; padding-left: 1%; font-size: 80% } .middle-panel-save-1 { width: 0%; float: left; padding-left: 1%; font-size: 80% } </style> --- class: split-40 count: false .left-panel-save1-1[ ```r ggsave(filename = "figures/my_plot1.png", plot = g, height = 5, width = 8) knitr::include_graphics(path = "figures/my_plot1.png") ``` ] .right-panel-save1-1[ <img src="figures/my_plot1.png" width="100%" /> ] <style> .left-panel-save1-1 { color: #777; width: 38.6138613861386%; height: 92%; float: left; font-size: 80% } .right-panel-save1-1 { width: 59.4059405940594%; float: right; padding-left: 1%; font-size: 80% } .middle-panel-save1-1 { width: 0%; float: left; padding-left: 1%; font-size: 80% } </style> --- class: split-40 count: false .left-panel-save2-1[ ```r ggsave(filename = "figures/my_plot2.png", plot = g, height = 5, width = 8, dpi = 30) knitr::include_graphics(path = "figures/my_plot2.png") ``` ] .right-panel-save2-1[ <img src="figures/my_plot2.png" width="100%" /> ] <style> .left-panel-save2-1 { color: #777; width: 38.6138613861386%; height: 92%; float: left; font-size: 80% } .right-panel-save2-1 { width: 59.4059405940594%; float: right; padding-left: 1%; font-size: 80% } .middle-panel-save2-1 { width: 0%; float: left; padding-left: 1%; font-size: 80% } </style> --- class: split-40 count: false .left-panel-save3-1[ ```r ggsave(filename = "figures/my_plot3.png", plot = g, height = 5, width = 8, dpi = 300) # max knitr::include_graphics(path = "figures/my_plot3.png") ``` ] .right-panel-save3-1[ <img src="figures/my_plot3.png" width="100%" /> ] <style> .left-panel-save3-1 { color: #777; width: 38.6138613861386%; height: 92%; float: left; font-size: 80% } .right-panel-save3-1 { width: 59.4059405940594%; float: right; padding-left: 1%; font-size: 80% } .middle-panel-save3-1 { width: 0%; float: left; padding-left: 1%; font-size: 80% } </style> --- class: split-40 count: false .left-panel-save4-1[ ```r ggsave(filename = "figures/my_plot4.png", units = "in", plot = g, height = 5, width = 8, dpi = 300) # max knitr::include_graphics(path = "figures/my_plot4.png") ``` ] .right-panel-save4-1[ <img src="figures/my_plot4.png" width="100%" /> ] <style> .left-panel-save4-1 { color: #777; width: 38.6138613861386%; height: 92%; float: left; font-size: 80% } .right-panel-save4-1 { width: 59.4059405940594%; float: right; padding-left: 1%; font-size: 80% } .middle-panel-save4-1 { width: 0%; float: left; padding-left: 1%; font-size: 80% } </style> --- class: split-40 count: false .left-panel-save5-1[ ```r ggsave(filename = "figures/my_plot5.png", units = "in", plot = g, height = 8, width = 8, dpi = 300) # max knitr::include_graphics(path = "figures/my_plot5.png") ``` ] .right-panel-save5-1[ <img src="figures/my_plot5.png" width="100%" /> ] <style> .left-panel-save5-1 { color: #777; width: 38.6138613861386%; height: 92%; float: left; font-size: 80% } .right-panel-save5-1 { width: 59.4059405940594%; float: right; padding-left: 1%; font-size: 80% } .middle-panel-save5-1 { width: 0%; float: left; padding-left: 1%; font-size: 80% } </style> --- class: split-40 count: false .left-panel-save6-1[ ```r ggsave(filename = "figures/my_plot6.png", units = "in", plot = g, height = 8, width = 5, dpi = 300) knitr::include_graphics(path = "figures/my_plot6.png") ``` ] .right-panel-save6-1[ <img src="figures/my_plot6.png" width="100%" /> ] <style> .left-panel-save6-1 { color: #777; width: 38.6138613861386%; height: 92%; float: left; font-size: 80% } .right-panel-save6-1 { width: 59.4059405940594%; float: right; padding-left: 1%; font-size: 80% } .middle-panel-save6-1 { width: 0%; float: left; padding-left: 1%; font-size: 80% } </style> --- class: split-40 count: false .left-panel-save7-1[ ```r ggsave(filename = "figures/my_plot7.png", units = "in", plot = g, height = 8, width = 5, * dpi = 50) knitr::include_graphics(path = "figures/my_plot7.png") ``` ] .right-panel-save7-1[ <img src="figures/my_plot7.png" width="100%" /> ] <style> .left-panel-save7-1 { color: #777; width: 38.6138613861386%; height: 92%; float: left; font-size: 80% } .right-panel-save7-1 { width: 59.4059405940594%; float: right; padding-left: 1%; font-size: 80% } .middle-panel-save7-1 { width: 0%; float: left; padding-left: 1%; font-size: 80% } </style> --- class: split-40 count: false .left-panel-save8-1[ ```r ggsave(filename = "figures/my_plot8.png", units = "in", plot = g, height = 8, width = 5, * dpi = 20) knitr::include_graphics(path = "figures/my_plot8.png") ``` ] .right-panel-save8-1[ <img src="figures/my_plot8.png" width="100%" /> ] <style> .left-panel-save8-1 { color: #777; width: 38.6138613861386%; height: 92%; float: left; font-size: 80% } .right-panel-save8-1 { width: 59.4059405940594%; float: right; padding-left: 1%; font-size: 80% } .middle-panel-save8-1 { width: 0%; float: left; padding-left: 1%; font-size: 80% } </style> --- Next up is [composition](ensembles.html) -- plot ensembles my help tell your stories. <style type="text/css"> .remark-code{line-height: 1.5; font-size: 60%} </style>