Graphics Reference
In-Depth Information
NOTE
Inkscape might have some issues with fonts as well. You may have noticed that the fonts in Figure 14-1
don't look quite right. This is because Inkscape (version 0.48) couldn't find Helvetica, and substituted
the font Bitstream Vera Sans instead. A workaround is to copy the Helvetica font file to your personal
font library. For example, on Mac OS X, run cp /System/Library/Fonts/Helvetica.dfont
~/Library/Fonts/ from a Terminal window to do this, then, when it says there is a font conflict, click
“Ignore Conflict.” After this, Inkscape should properly display the Helvetica font.
Outputting to Bitmap (PNG/TIFF) Files
Problem
You want to create a bitmap of your plot, writing to a PNG file.
Solution
There are two ways to output to PNG bitmap files. One method is to open the PDF graphics
device with png() , 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 pixels
png( "myplot.png" , width = 400 , height = 400 )
# Make plot
plot(mtcars$wt, mtcars$mpg)
dev.off()
For outputting multiple plots, put %d in the filename. This will be replaced with 1, 2, 3, and so
on, for each subsequent plot:
# width and height are in pixels
png( "myplot-%d.png" , width = 400 , height = 400 )
plot(mtcars$wt, mtcars$mpg)
print(ggplot(mtcars, aes(x = wt, y = mpg)) + geom_point())
dev.off()
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.
Search WWH ::




Custom Search