This chapter starts with comments on the graphical devices that are available in R, on font families and fonts, on plotting symbols, and on R's color choices. It discusses the abilities in the lattice package in modest detail, with a more cursory discussion of the ggplot2 package.
Hardcopy graphics devices
The following writes the graph to the pdf file fossilfuel.pdf:
pdf(file=“fossilfuel.pdf”, width=6.5, height=6.5, pointsize=18)
# For pdf() and postscript(), heights and widths are in inches plot(carbon ˜ year, data=fossilfuel, pch=16) dev.off()
Other functions that open hardcopy graphics devices include png(), jpeg(), bmp(), and tiff(). Unless the default units=“px” is changed, height and width are in pixels. Use dev.off() to close the device, thus making the file available for display, or for printing, or for incorporation into a document. For a complete list of devices, and further details of specific devices, see help(Devices).
Subsection 1.5.4 described commands used to open graphics windows on commonly used implementations of R. Use dev.copy() to copy a graph from the display that is currently active to a hardcopy graphics device. For example:
plot(carbon ˜ year, data=fossilfuel, pch=16) # Display graph ## Now open pdf device and copy graph to it
dev.copy(pdf, file=“fossilcopy.pdf”)