From the course: R for Data Science: Lunch Break Lessons

Unlock this course with a free trial

Join today to access over 22,500 courses taught by industry experts.

Plot to file

Plot to file

- [Instructor] You'll often want to save plots, out to a file that you can then incorporate in other reports and RStudio and R gives you a couple of ways to do this. If you're using RStudio you can just simply just generate a plot, and then go down to the plot panel in the lower right hand corner, and use the Export menu to either Save as an Image, Save as PDF or Copy to Clipboard and that works great. However, there are times when either you are not using RStudio or you may wanna do this programmatically. Now you can save out as a JPEG, or PNG, or a WMF, or a PDF let's take a look at how to do this as a PDF and then I'll explain how to change the file format that you use later on. The first thing when you're outputting graphics to a file is declare what kind of a file you wanna create. In this case, I wanna create a PDF file so I type in pdf and the first thing that I need to do, is declare where I want to store that image file. I'm gonna save it in my home directory, and the tilde's…

Contents