ggplot2 themes for publication ready plots; including dark themes

Koundinya Desiraju
Analytics Vidhya
Published in
4 min readMay 1, 2020

ggplot2 by Hadley is a very good package for data visualization in R. However the default plots made by the package requires some formatting before we can send them for publication. The package ggthemes, written by Jeffrey for this purpose and provides some nice themes. But I want to try myself and improvise on the this. So, I have written some of my own themes (of course with the help of in-built functions from ggthemes thanks to Jeffrey). All these themes are available on this GitHub repository. In this post, I will discuss the motivation behind my themes and demonstrate them. You can follow these simple steps and use these themes in your own projects.

My problems with the default aesthetics of ggplot are

  • Plot background
  • Title and axes labels Font and size
  • Axes themselves
  • Axis ticks
  • Colors
  • Legend position
  • Default color palette

So, here I tried to fix each one of them and create my own themes and color palette. There are 3 themes in total. The first theme, theme_Publication, is a bright theme with focus on making publication ready figures straight from ggplot2. The other two themes, theme_dark_bue and theme_dark_grey , are dark themes following the trend of the dark themes everywhere :). As the screens on most of the devices getting better and more color accurate, the dark themes are popping up in all operating systems, apps and code editors. These themes are meant to be used for visualisation in your dark themed IDEs (like Rstudio). The dark themes are also great for presentations especially when you use slides with dark background.

All of these themes will produce

  • Plots with bold axes and axes labels.
  • Legend is placed at the bottom leaving extra space for the plotting area.
  • The color palette with bold and contrasting colors, designed with the help of color brewer, to easily distinguish any two colors .

Examples of plots with theme_Publication

library(tidyverse)
library(gridExtra)
source('~/ggplot_theme_Publication-2.R')
Scatter <- ggplot(mtcars, aes(mpg,disp,color=factor(carb))) + geom_point(size=3) + labs(title="Scatter Plot")

grid.arrange(Scatter,(Scatter +scale_colour_Publication()+ theme_Publication()),nrow=1)
Bar <- ggplot(mtcars, aes(factor(carb),fill=factor(carb))) + geom_bar(alpha=0.7) + labs(title="Bar Plot")

grid.arrange(Bar,(Bar + scale_fill_Publication() +theme_Publication()),nrow=1)
Bubble <- ggplot(mtcars, aes(mpg,disp,color=factor(carb),size=hp)) + geom_point(alpha=0.7) + labs(title="Bubble Plot") + scale_size_continuous(range = c(3,10))

grid.arrange(Bubble,(Bubble +scale_colour_Publication()+ theme_Publication()),nrow=1)
library(reshape2)
mtcars$Index <- 1:nrow(mtcars)
dat <- melt(mtcars,id.vars = c("Index"),measure.vars = c("drat","wt"))
Line <- ggplot(dat,aes(Index,value,colour=variable))+geom_line(size=1.3) + labs(title="Line Plot")
grid.arrange(Line,(Line +scale_colour_Publication()+ theme_Publication()),nrow=1)
P <- ggplot(data = mpg,aes(cty, hwy,color=class))+geom_point(size=3) + facet_wrap(~ manufacturer,scales="free")+
labs(title="Plot With Facets")
P
P +scale_colour_Publication()+ theme_Publication()

Examples of plots with theme_dark_blue and theme_dark_grey

grid.arrange((Scatter + scale_colour_Publication() + theme_dark_blue()),
(Scatter + scale_colour_Publication() + theme_dark_grey()),nrow=1)
grid.arrange((Bar + scale_fill_Publication() + theme_dark_blue()),
(Bar + scale_fill_Publication() + theme_dark_grey()),nrow=1)
grid.arrange((Bubble + scale_colour_Publication() + theme_dark_blue()),
(Bubble + scale_colour_Publication() + theme_dark_grey()),nrow=1)
grid.arrange((Line + scale_colour_Publication() + theme_dark_blue()),
(Line + scale_colour_Publication() + theme_dark_grey()),nrow=1)
P +scale_colour_Publication()+ theme_dark_grey()
P +scale_colour_Publication()+ theme_dark_blue()

--

--

Koundinya Desiraju
Analytics Vidhya

A Physician data scientist. Creating applications of #AI in #Healthcare towards achieving #AffordableHealth #HealthForAll #UHC