Themes that comes from severals packages gathered by thomas-neitmann / mdthemes

if (!"remotes" %in% installed.packages()) {
  install.packages("remotes")
}
remotes::install_github("thomas-neitmann/mdthemes", upgrade = "never")
library(ggplot2)
library(mdthemes)
data(mtcars)

1 DEFAULT

p <- ggplot(mtcars, aes(hp, mpg)) +
  geom_point()

p

1.1 Modify components of a theme

1.2 The function

the theme_gray function

function (base_size = 11, 
          base_family = "", 
          base_line_size = base_size/22, 
          base_rect_size = base_size/22) 
{
  half_line <- base_size/2
  
  t <- theme(line = element_line(colour = "black", size = base_line_size, 
                                 linetype = 1, lineend = "butt"), 
             rect = element_rect(fill = "white", colour = "black", 
                                 size = base_rect_size, 
                                 linetype = 1),
             text = element_text(family = base_family, face = "plain", 
                                 colour = "black", size = base_size, lineheight = 0.9, 
                                 hjust = 0.5, vjust = 0.5, angle = 0, margin = margin(), 
                                 debug = FALSE), 
             axis.line = element_blank(),
             axis.line.x = NULL,
             axis.line.y = NULL,
             axis.text = element_text(size = rel(0.8), colour = "grey30"), 
             axis.text.x = element_text(margin = margin(t = 0.8 * half_line/2), vjust = 1), 
             axis.text.x.top = element_text(margin = margin(b = 0.8 * half_line/2), vjust = 0), 
             axis.text.y = element_text(margin = margin(r = 0.8 * half_line/2), hjust = 1), 
             axis.text.y.right = element_text(margin = margin(l = 0.8 * half_line/2), hjust = 0), 
             axis.ticks = element_line(colour = "grey20"),
             axis.ticks.length = unit(half_line/2, "pt"), 
             axis.ticks.length.x = NULL, 
             axis.ticks.length.x.top = NULL, 
             axis.ticks.length.x.bottom = NULL, 
             axis.ticks.length.y = NULL, 
             axis.ticks.length.y.left = NULL, 
             axis.ticks.length.y.right = NULL, 
             axis.title.x = element_text(margin = margin(t = half_line/2), vjust = 1), 
             axis.title.x.top = element_text(margin = margin(b = half_line/2), vjust = 0), 
             axis.title.y = element_text(angle = 90, 
                                                 margin = margin(r = half_line/2), vjust = 1), 
             axis.title.y.right = element_text(angle = -90, 
                                               margin = margin(l = half_line/2), vjust = 0), 
             legend.background = element_rect(colour = NA), 
             legend.spacing = unit(2 * half_line, "pt"), legend.spacing.x = NULL, 
             legend.spacing.y = NULL, legend.margin = margin(half_line, 
                                                             half_line, half_line, half_line), 
             legend.key = element_rect(fill = "grey95", colour = NA), 
             legend.key.size = unit(1.2, "lines"), 
             legend.key.height = NULL, legend.key.width = NULL, 
             legend.text = element_text(size = rel(0.8)), 
             legend.text.align = NULL, 
             legend.title = element_text(hjust = 0), 
             legend.title.align = NULL, 
             legend.position = "right", 
             legend.direction = NULL, 
             legend.justification = "center", 
             legend.box = NULL, 
             legend.box.margin = margin(0, 0, 0, 0, "cm"), 
             legend.box.background = element_blank(), 
             legend.box.spacing = unit(2 * half_line, "pt"), 
             panel.background = element_rect(fill = "grey92", colour = NA), 
             panel.border = element_blank(), 
             panel.grid = element_line(colour = "white"), 
             panel.grid.minor = element_line(size = rel(0.5)), 
             panel.spacing = unit(half_line, "pt"), 
             panel.spacing.x = NULL, 
             panel.spacing.y = NULL, 
             panel.ontop = FALSE, 
             strip.background = element_rect(fill = "grey85", colour = NA), 
             strip.text = element_text(colour = "grey10", 
                                       size = rel(0.8),
                        margin = margin(0.8 * half_line, 0.8 * half_line, 
                                        0.8 * half_line, 0.8 * half_line)), 
             strip.text.x = NULL, strip.text.y = element_text(angle = -90), 
             strip.text.y.left = element_text(angle = 90), 
             strip.placement = "inside", 
             strip.placement.x = NULL, 
             strip.placement.y = NULL, 
             strip.switch.pad.grid = unit(half_line/2, "pt"), 
             strip.switch.pad.wrap = unit(half_line/2, "pt"), 
             plot.background = element_rect(colour = "white"), 
             plot.title = element_text(size = rel(1.2), hjust = 0, 
                                       vjust = 1, margin = margin(b = half_line)), 
             plot.title.position = "panel", 
             plot.subtitle = element_text(hjust = 0, vjust = 1, 
                                          margin = margin(b = half_line)), 
             plot.caption = element_text(size = rel(0.8), hjust = 1, 
                                         vjust = 1, margin = margin(t = half_line)), 
             plot.caption.position = "panel", 
             plot.tag = element_text(size = rel(1.2), hjust = 0.5, 
                                     vjust = 0.5), 
             plot.tag.position = "topleft",
             plot.margin = margin(half_line, half_line, 
                                  half_line, half_line), complete = TRUE)
  ggplot_global$theme_all_null %+replace% t
}

2 GGPLOT Themes

  • with basic labs configurations
# With labs configuration
p + md_theme_gray() +
  labs(
    title = "<span style = 'color:blue'> A blue Title </span>",
    subtitle = "And an *italics* subtitle",
    x = "**_hp_**", # italic and black
    caption = "<span style = 'color:red'>A red caption</span>")

p + md_theme_grey()

p + md_theme_bw()

p + md_theme_linedraw()

p + md_theme_light()

p + md_theme_dark()

p + md_theme_minimal()

p + md_theme_classic()

3 COWPLOT

p + md_theme_cowplot()

p + md_theme_half_open()

p + md_theme_map_cow()

p + md_theme_minimal_grid()

p + md_theme_minimal_hgrid()

p + md_theme_minimal_vgrid()

p + md_theme_nothing()

4 GGTHEMES

p + md_theme_base()

p + md_theme_calc()

p + md_theme_clean()

p + md_theme_economist()

p + md_theme_economist_white()

p + md_theme_excel()

p + md_theme_excel_new()

p + md_theme_few()

p + md_theme_fivethirtyeight()

p + md_theme_foundation()

p + md_theme_gdocs()

p + md_theme_hc()

p + md_theme_igray()

p + md_theme_map_gg()

p + md_theme_pander()

p + md_theme_par()

p + md_theme_solarized()

p + md_theme_solarized_2()

# p + md_theme_solid()
p + md_theme_stata()

p + md_theme_tufte()

p + md_theme_wsj()

5 hrbrthemes

p + md_theme_ft_rc()

p + md_theme_ipsum()

p + md_theme_ipsum_ps()

p + md_theme_ipsum_rc()

p + md_theme_ipsum_tw()

p + md_theme_modern_rc()

6 tvthemes

p + md_theme_avatar()

p + md_theme_brooklyn99()

p + md_theme_hildaDay()

p + md_theme_hildaDusk()

p + md_theme_hildaNight()

p + md_theme_parksAndRec()

p + md_theme_parksAndRec_light()

p + md_theme_parksAndRecLight()

p + md_theme_rickAndMorty()

p + md_theme_simpsons()

p + md_theme_spongeBob()

p + md_theme_theLastAirbender()