Saving Plots and Images in R

Process

If you generate a plot in R and want to save it, then you would typically use the following protocol:

png(file = FILEPATH)

plot(    )

dev.off()

Unfortunately, using this approach on the Grid does not work for the most common image types (PNG, JPG, and TIFF). However, you may store your plots as BMP or bitmap. To do so, follow this syntax:

bitmap(file = FILEPATH)

plot(    )

dev.off()

To view your plots, you may either transfer the files to your local machine, or map/mount the Grid folder to your local PC/Mac, then view the files as you would any other.

For further information on either option, please visit http://grid.rcs.hbs.org/accessing-spaces-folders-gui

Example Working Code

The following code will generate a histogram with light green bars. The resulting bitmap will be saved as “testplot.bmp” to your home directory (“~/” denotes home directory)

x=rnorm(50, mean=0, sd=1)

bitmap(file=”~/testplot.bmp”)

hist(x, breaks=10, col=’lightgreen’)

dev.off()