Making figures in R

Useful resources and tutorials for visualising data using R.

General resources

Colour palettes

  • viridis

    A pretty and colour-blind friendly palette!

  • ggsci

    ggsci has some colour palettes based on various journals if you’re feeling fancy, or more excitingly some based on things like star trek…

  • Pride Palettes

    Pride flag colour schemes!

Graph types

  • Eulerr

    If you are struggling with venn diagrams that aren’t proportional, Eulerr can provide a fix. It makes area-proportional diagrams, or if that is impossible, a good approximation with included goodness-of-fit stats! (Euler diagrams are very similar to venn diagrams, they just don’t require every set to interact.)

  • Heatmaps

    A useful primer on what heatmaps actually tell us.

  • Upset plots

    If you have lots of groups in your data, and venn diagrams turn into a massive confusing mess, that’s the time to try an upset plot. They use a matrix to represent different intersections, and a bar plot to visualise the number of elements in each intersection. You can also get fancy and introduce queries or extra plots that describe different features of your data.

  • ggstatsplot

    This package runs statistical tests, and creates plots with them included. It also makes lovely violin/box plot combinations which are much more informative than a straightforward box plot.

  • ggbeeswarm

    Are the points in your violin scatter plots overlapping so you can’t see all the data? Ta-da, ggbeeswarm fixed it! You can also find a great tutorial for ggbeeswarm here: Bee Swarm Charts in R.

  • ggplot2 extensions

    All the extensions mentioned above and more!

Online Textbooks

Some other pointers

Some of these pointers may not make sense until you’re trying to make a certain plot, they’re gathered here in the hopes they are useful.

  • If you use xlim/ylim or scale_y_continous() to zoom in on a boxplot, ggplot recalculates the range etc based on that limit. If you want to include the outliers but just zoom in without recalculation, use coord_cartesian() to change the limits.

  • In ggplot, discrete missing values are displayed. Adding scale_color_discrete(na.translate = FALSE) removes them. See tweet source for details.