Graphics display issues with R built from source for RStudio Server

I believe that the default graphical device to which graphical output is sent is an X display, which rasterizes the imag. Using

options(bitmapType=‘cairo’)

instructs R to use the cairo rasterizer to create the plot instead of the X device. You might find something useful at

https://stat.ethz.ch/R-manual/R-devel/library/grDevices/html/Devices.html

Just in case it comes up, users can change the bitmapType by including the options() command above with the desired type.

In the following snippet, I set the device to an invalid one, and R prints a list of what it knows about. Using any of the devices that work on Linux and don’t require a display should work (quartz is obviously OS X).

require(ggplot2)
Loading required package: ggplot2
df ← data.frame(x=1:10,y=1:10)
plot(df)
ggplot(df,aes(x=x,y=y)) + geom_point()

options(bitmapType=‘x11’)
ggsave(‘/tmp/jtb49/foo.png’)
Saving 7 x 7 in image
Error in match.arg(type) :
‘arg’ should be one of “cairo”, “cairo-png”, “Xlib”, “quartz”

options(bitmapType=‘Xlib’)
ggsave(‘/tmp/foo.png’)
Saving 7 x 7 in image
Error in .External2(C_X11, paste0(“png::”, filename), g$width, g$height, :
unable to start device PNG
In addition: Warning message:
In grDevices::png(…, res = dpi, units = “in”) :
unable to open connection to X11 display ‘’

options(bitmapType=‘cairo-png’)
ggsave(‘/tmp/foo.png’)

Saving 7 x 7 in image

options(bitmapType=‘cairo’)
ggsave(‘/tmp/foo.png’)
Saving 7 x 7 in image

1 Like