In the section on further customization, themes are discussed.

For the plot we have made for the Beatles some themes are experimented with.

library(tidyverse)
library(mdsr)
library(babynames)
Beatles <- babynames %>%
  filter(name %in% c("John", "Paul", "George", "Ringo") & sex == "M")
beatles_plot <- Beatles %>% ggplot(aes(x = year, y = n)) +
  geom_line(aes(color = name), size = 2)
beatles_plot

beatles_plot + theme_grey()

beatles_plot + theme_bw()

beatles_plot + theme_minimal()

beatles_plot + theme_classic()

beatles_plot + theme(panel.background = element_rect(fill = "cornsilk"),
                     panel.grid.major = element_line(color = "dodgerblue"))

The theme used in the book.

Note the use of **%+replace%*.

theme_mdsr <- function(base_size = 12, base_family = "Bookman"){
  theme_grey(base_size = base_size, base_family = base_family) %+replace%
    theme(
      axis.text = element_text(size = rel(0.8)),
      axis.ticks = element_line(colour = "black"),
      legend.key = element_rect(colour = "grey80"),
      panel.background = element_rect(fill = "whitesmoke", colour = NA),
      panel.border = element_rect(fill = NA, colour = "grey50"),
      panel.grid.major = element_line(colour = "grey80", size = 0.2),
      panel.grid.minor = element_line(colour = "grey92", size = 0.5),
      strip.background = element_rect(fill = "grey80", colour = "grey50", size = 0.2)
    )
}
beatles_plot + theme_mdsr()

beatles_plot + facet_wrap(~name) + theme_mdsr()

Load the package ggthemes.

library(ggthemes)
beatles_plot + facet_wrap(~name) + theme_solarized()

beatles_plot + facet_wrap(~name) + theme_tufte()

beatles_plot + facet_wrap(~name) + theme_fivethirtyeight()

beatles_plot + facet_wrap(~name) + theme_excel()

Here is the xkcd web comic.

To get started with the xkcd fonts you start by reading the vignette.

vignette("xkcd-intro")

Run this code once.

download.file("http://simonsoftware.se/other/xkcd.ttf",
    dest="xkcd.ttf", mode="wb")
trying URL 'http://simonsoftware.se/other/xkcd.ttf'
Content type 'application/x-font-ttf' length 12712 bytes (12 KB)
==================================================
downloaded 12 KB
system("mkdir ~/.fonts")
mkdir: cannot create directory ‘/home/esuess/.fonts’: File exists
system("cp xkcd.ttf ~/.fonts")
font_import(pattern = "[X/x]kcd", prompt=FALSE)
Scanning ttf files in /usr/share/fonts/, ~/.fonts/ ...
Extracting .afm files from .ttf files...
/home/esuess/.fonts/xkcd.ttf : xkcd already registered in fonts database. Skipping.
Found FontName for 0 fonts.
Scanning afm files in /home/esuess/R/x86_64-pc-linux-gnu-library/3.4/extrafontdb/metrics
fonts()
[1] "xkcd"
fonttable()
library(xkcd)
library(extrafont)
beatles_plot + theme_xkcd()

Hand drawn axis.

 xrange <- range(mtcars$mpg)
 yrange <- range(mtcars$wt)
 set.seed(123) # for reproducibility
 p <- ggplot() + geom_point(aes(mpg, wt), data=mtcars) +
    xkcdaxis(xrange,yrange)
 p

Comic looking plots.

ratioxy <- diff(xrange)/diff(yrange)
   mapping <- aes(x, y, scale, ratioxy, angleofspine,
   anglerighthumerus, anglelefthumerus,
   anglerightradius, angleleftradius,
   anglerightleg, angleleftleg, angleofneck,
   linetype=city)
Duplicated aesthetics after name standardisation: 
dataman <- data.frame(x= c(15,30), y=c(3, 4),
  scale = c(0.3,0.51) ,
  ratioxy = ratioxy,
  angleofspine = -pi/2 ,
  anglerighthumerus = c(pi/4, -pi/6),
  anglelefthumerus = c(pi/2 + pi/4, pi +pi/6),
  anglerightradius = c(pi/3, -pi/3),
  angleleftradius = c(pi/3, -pi/3),
  anglerightleg = 3*pi/2 - pi / 12,
  angleleftleg = 3*pi/2 + pi / 12 ,
  angleofneck = runif(1, 3*pi/2-pi/10, 3*pi/2+pi/10),
  city=c("Liliput","Brobdingnag"))
p <- ggplot() + geom_point(aes(mpg, wt, colour=as.character(vs)), data=mtcars) +
  xkcdaxis(xrange,yrange) +
  xkcdman(mapping, dataman)
p

One more dynamic graphics library, that is from Python, R bokeh.

library(rbokeh)
p1 <- figure(width = 800, height = 400) %>%
  ly_points(year, n, data = Beatles, color = name, glyph = name, hover = list(year, n, name))
Calling 'structure(NULL, *)' is deprecated, as NULL cannot have attributes.
  Consider 'structure(list(), *)' instead.Calling 'structure(NULL, *)' is deprecated, as NULL cannot have attributes.
  Consider 'structure(list(), *)' instead.Calling 'structure(NULL, *)' is deprecated, as NULL cannot have attributes.
  Consider 'structure(list(), *)' instead.Calling 'structure(NULL, *)' is deprecated, as NULL cannot have attributes.
  Consider 'structure(list(), *)' instead.Calling 'structure(NULL, *)' is deprecated, as NULL cannot have attributes.
  Consider 'structure(list(), *)' instead.Calling 'structure(NULL, *)' is deprecated, as NULL cannot have attributes.
  Consider 'structure(list(), *)' instead.Calling 'structure(NULL, *)' is deprecated, as NULL cannot have attributes.
  Consider 'structure(list(), *)' instead.Calling 'structure(NULL, *)' is deprecated, as NULL cannot have attributes.
  Consider 'structure(list(), *)' instead.Calling 'structure(NULL, *)' is deprecated, as NULL cannot have attributes.
  Consider 'structure(list(), *)' instead.Calling 'structure(NULL, *)' is deprecated, as NULL cannot have attributes.
  Consider 'structure(list(), *)' instead.
p1
Calling 'structure(NULL, *)' is deprecated, as NULL cannot have attributes.
  Consider 'structure(list(), *)' instead.Calling 'structure(NULL, *)' is deprecated, as NULL cannot have attributes.
  Consider 'structure(list(), *)' instead.Calling 'structure(NULL, *)' is deprecated, as NULL cannot have attributes.
  Consider 'structure(list(), *)' instead.Calling 'structure(NULL, *)' is deprecated, as NULL cannot have attributes.
  Consider 'structure(list(), *)' instead.Calling 'structure(NULL, *)' is deprecated, as NULL cannot have attributes.
  Consider 'structure(list(), *)' instead.Calling 'structure(NULL, *)' is deprecated, as NULL cannot have attributes.
  Consider 'structure(list(), *)' instead.Calling 'structure(NULL, *)' is deprecated, as NULL cannot have attributes.
  Consider 'structure(list(), *)' instead.Calling 'structure(NULL, *)' is deprecated, as NULL cannot have attributes.
  Consider 'structure(list(), *)' instead.

p2 <- figure(width = 800, height = 400) %>%
  ly_lines(x = year, y = n, group = name, data = Beatles, color = name, hover = list(year, n, name))
Calling 'structure(NULL, *)' is deprecated, as NULL cannot have attributes.
  Consider 'structure(list(), *)' instead.Calling 'structure(NULL, *)' is deprecated, as NULL cannot have attributes.
  Consider 'structure(list(), *)' instead.Calling 'structure(NULL, *)' is deprecated, as NULL cannot have attributes.
  Consider 'structure(list(), *)' instead.Calling 'structure(NULL, *)' is deprecated, as NULL cannot have attributes.
  Consider 'structure(list(), *)' instead.Calling 'structure(NULL, *)' is deprecated, as NULL cannot have attributes.
  Consider 'structure(list(), *)' instead.Calling 'structure(NULL, *)' is deprecated, as NULL cannot have attributes.
  Consider 'structure(list(), *)' instead.Calling 'structure(NULL, *)' is deprecated, as NULL cannot have attributes.
  Consider 'structure(list(), *)' instead.Calling 'structure(NULL, *)' is deprecated, as NULL cannot have attributes.
  Consider 'structure(list(), *)' instead.Calling 'structure(NULL, *)' is deprecated, as NULL cannot have attributes.
  Consider 'structure(list(), *)' instead.Calling 'structure(NULL, *)' is deprecated, as NULL cannot have attributes.
  Consider 'structure(list(), *)' instead.
p2
Calling 'structure(NULL, *)' is deprecated, as NULL cannot have attributes.
  Consider 'structure(list(), *)' instead.Calling 'structure(NULL, *)' is deprecated, as NULL cannot have attributes.
  Consider 'structure(list(), *)' instead.Calling 'structure(NULL, *)' is deprecated, as NULL cannot have attributes.
  Consider 'structure(list(), *)' instead.Calling 'structure(NULL, *)' is deprecated, as NULL cannot have attributes.
  Consider 'structure(list(), *)' instead.Calling 'structure(NULL, *)' is deprecated, as NULL cannot have attributes.
  Consider 'structure(list(), *)' instead.Calling 'structure(NULL, *)' is deprecated, as NULL cannot have attributes.
  Consider 'structure(list(), *)' instead.Calling 'structure(NULL, *)' is deprecated, as NULL cannot have attributes.
  Consider 'structure(list(), *)' instead.Calling 'structure(NULL, *)' is deprecated, as NULL cannot have attributes.
  Consider 'structure(list(), *)' instead.
LS0tCnRpdGxlOiAiZ2dwbG90MiB0aGVtZXMiCm91dHB1dDogaHRtbF9ub3RlYm9vawotLS0KCkluIHRoZSBzZWN0aW9uIG9uIGZ1cnRoZXIgY3VzdG9taXphdGlvbiwgdGhlbWVzIGFyZSBkaXNjdXNzZWQuCgpGb3IgdGhlIHBsb3Qgd2UgaGF2ZSBtYWRlIGZvci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