Save your graph
Basic rules
-
To save your graph in a png format, (1) start with the command png( ); (2) draw your graph (e.g., plot(x,y), hist(x) or whatever); (3) end with the command, dev.off().
> png(file="c:/YOUR-DIRECTORY/filename.png") > plot(x,y) > dev.off()
-
YOUR-DIRECTORY: Note that the "forward slash" / shoud be used in defining your directory. MS Windows use back slash as default.
A typical full path for your Desktop directory:
- In Win-XP,
it is C:/Documents and Settings/YOUR_ID/Desktop/.
- In Linux,
it is usually /home/YOUR_ID/Desktop/.
- In Macintosh,
it is usually /Users/YOUR_ID/Desktop/.
-
To change the size of your graph, use width and height options. Note that the graph size displayed on your monitor won't be changed by these commands, but only the graph size you saved in your machine is changed. To sharpen your graph, use res option.
> png(file="c:/YOUR-DIRECTORY/filename.png", width=400, height=300, res=100) > plot(x,y) > dev.off()
Formats of graph files
-
Various formats are available. I recommend to use a "png" or "jpg" format that can be properly displayed in any machine (PC, Linux, and [probably] Mac [too]).
> png(file="filename.png") > jpeg(file="filename.jpg") > pdf(file="filename.pdf") > bmp(file="filename.bmp") > win.metafile("filename.wmf")
[ Going back to Using R: Index ]