Plotting in R

Plotting for R is a major selling point of the platform. And thanks to projects like shiny it is not only for your own computer but can even be used to backend webapps.


Basic r plotting via the plot command is functional.


More tidyverse! Probably the favourite plotting system for R these days.

Kieran Healy advises the following set up for visualisation in the tidyverse style :

my_packages <- c("tidyverse", "broom", "coefplot", "cowplot",
    "gapminder", "GGally", "ggrepel", "ggridges",X "gridExtra",
    "interplot", "margins", "maps", "mapproj", "mapdata",
    "MASS", "quantreg", "scales", "survey", "srvyr",
    "viridis", "viridisLite", "devtools")

    repos = "")


Browser-backed option Plotly has R support. See plotly.

Other plotting systems

R Graphical Manual visualization of all CRAN R package example plots, and is searchable by topic.

Other image wrangling

meme produces image macros from inside R. hexSticker does hexStickers.

Spatial data and maps and such

See maps in R.

cairo errors

Do you get an error like this when plotting SVGs?

unable to load shared object '/usr/local/Cellar/r/3.5.0_1/lib/R/library/grDevices/libs//':
dlopen(/usr/local/Cellar/r/3.5.0_1/lib/R/library/grDevices/libs//, 6): image not found

Or this?

Error in dev.control(displaylist = if (record) "enable" else "inhibit") :
  dev.control() called without an open graphics device
Calls: local ... call_block -> block_exec -> chunk_device -> dev.control
In addition: Warning messages:
1: In (function (filename = if (onefile) "Rplots.svg" else "Rplot%03d.svg",  :
  unable to load shared object 'SOMETHING/r/3.6.2/lib/R/library/grDevices/libs//':
  dlopen(SOMETHING/r/3.6.2/lib/R/library/grDevices/libs//, 6): image not found

Cairo is finicky.

One problem can be that homebrew R doesn’t support the cairo library. Yihui recommends:

brew install --cask r

or you can install svglite as an alternative plotting backend


and use the device option dev = "svglite". Mind you, svglite can have its own problems. I needed to do the following, on one Kubuntu workstation,


On macOS, XQuartz helps

brew install --cask xquartz

Although I suspect it is a bloated security risk so avoid if poss; XQuartz is a community maintained fork of a notoriously insecure piece of software that runs as root, so it would be a an embarrassing way to get p3ned.

For anaconda R, this seems to help:

conda update conda
conda update --all
conda install -c r r-essentials=1.7.0

Generally anaconda R is a nightmare though, and all sorts of things fail to compile for me, so I do not recommend it.

1 comment

Yogesh Gupta


I m getting below error in R on HPC. if I check r capabilities then it shows png, Cairo, x11 as False.

Could you please how I can resolve below error on HPC?

Error in dev.control(displaylist = "enable") : dev.control() called without an open graphics device Calls: ... new -> initialize -> initialize -> .local -> dev.control In addition: There were 50 or more warnings (use warnings() to see the first 50) Execution halted

Many thanks Yogesh

Reply to Yogesh Gupta

GitHub-flavored Markdown & a sane subset of HTML is supported.