Plotting for R is a major selling point o fthe whole platform. And thanks to projects like shiny it is not only for your own computer but can even be used to backend webapps.
ggplot2
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")
install.packages(my_packages,
repos = "http://cran.rstudio.com")
yonicd/ggedit: Interactively edit ggplot layer aesthetics and theme definitions.
ggedit is a package that helps users bridge the gap between making a plot and getting all of those pesky plot aesthetics just right, all while keeping everything portable for further research and collaboration.
ggedit is powered by a Shiny gadget where the user inputs a ggplot plot object or a list of ggplot objects. You can run ggedit directly from the console or from the Addin menu within RStudio.
The ggplot2 reference is thorough but inscrutable without knowing the philosophy of the thing.
Fancy features are best discovered via the extension gallery.
The cheat sheet has graphical references, which is the appropriate way to consider this thing.
Max Woolf’s simple ggplot tutorial
The ggplot chapter of R for data science.
Want arbitrary lines and stuff to appear in the legends? E.g. a mean line or multiple model fits.
diagrammer emits your graphs as javascript widgets. V Web2.0 wow.
ggvis is a planned next iteration of the Hadley Wickham’s ggplot family, AFAICT, but currently on hiatus
animating is sort of possible using ggplot2 but it is not fun.
gggedit is an interactive rstudio extension for dynamically adjsuting plots
plotly
Browser-backed option Plotly has R support.
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.
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//cairo.so':
dlopen(/usr/local/Cellar/r/3.5.0_1/lib/R/library/grDevices/libs//cairo.so, 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//cairo.so':
dlopen(SOMETHING/r/3.6.2/lib/R/library/grDevices/libs//cairo.so, 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.
install.packages("svglite")
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,
install.packages("devtools")
devtools::install_github('davidgohel/gdtools')
devtools::install_github("r-lib/svglite")
Or if you are using 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.