Graphics Reference
In-Depth Information
If you are creating plots from a script and it throws an error while creating one, R might not
reach the call to dev.off() , and could be left in a state where the PDF device is still open.
When this happens, the PDF file won't open properly until you manually call dev.off() .
If you are creating a graph with ggplot2, using ggsave() can be a little simpler. It simply saves
the last plot created with ggplot() :
ggplot(mtcars, aes(x = wt, y = mpg)) + geom_point()
# Default is inches, but you can specify unit
ggsave( "myplot.pdf" , width = 8 , height = 8 , units = "cm" )
With ggsave() , you don't need to print the ggplot object, and if there is an error while creating
or saving the plot, there's no need to manually close the graphic device. ggsave() can't be used
to make multipage plots, though.
Discussion
PDF files are usually the best option when your goal is to output to printed documents. They
work easily with LaTeX and can be used in presentations with Apple's Keynote, but Microsoft
programs may have trouble importing them. (See Outputting to WMF Vector Files for details on
creating vector images that can be imported into Microsoft programs.)
PDF files are also generally smaller than bitmap files such as portable network graphics (PNG)
files, because they contain a set of instructions, such as “Draw a line from here to there,” instead
of information about the color of each pixel. However, there are cases where bitmap files are
smaller. For example, if you have a scatter plot that is heavily overplotted, a PDF file can end up
much larger than a PNG—even though most of the points are obscured, the PDF file will still
contain instructions for drawing each and every point, whereas a bitmap file will not contain the
redundant information. See Dealing with Overplotting for an example.
See Also
If you want to manually edit the PDF or SVG file, see Editing a Vector Output File .
Outputting to SVG Vector Files
Problem
You want to create a scalable vector graphics (SVG) image of your plot.
Search WWH ::




Custom Search