Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.
There are two ways to output to PDF files. One method is to
open the PDF graphics device with pdf(), make the
plots, then close the device with dev.off(). This
method works for most graphics in R, including base graphics and
grid-based graphics like those created by ggplot2 and lattice:
# width and height are in inchespdf("myplot.pdf",width=4,height=4)# Make plotsplot(mtcars$wt,mtcars$mpg)print(ggplot(mtcars,aes(x=wt,y=mpg))+geom_point())dev.off()
If you make more than one plot, each one will go on a separate
page in the PDF output. Notice that we called print() on the
ggplot object to make sure that it will be output
even when this code is in a script.