custom_theme: Customized ggplot2 theme

Description Usage Arguments Value Note Author(s) See Also Examples

Description

This function makes presentation-ready ggplot2 plots when added as a theme to a ggplot2 function call.

Usage

1
custom_theme(base_size, base_family)

Arguments

base_size

Base font size for the plot. Optional; defaults to 18.

base_family

Font family for the plot. Optional; defaults to "serif".

Value

Returns a theme to stylize a ggplot2 graph.

Note

At present, an extra line space is needed after the plot title and before the x- and y-axis labels to make the plot look right. This is weird and needs fixing. See the example.

Author(s)

Erica Wozniak

See Also

reportR

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
library(ggplot2)

# Custom theme with defaults
ggplot(dat = cars, aes(x = speed, y = dist)) + 
  geom_point() + 
  ggtitle("Vehicle stopping distance vs speed\n") + 
  xlab("\nSpeed (mph)") + 
  ylab("\nStopping distance (ft)") + 
  custom_theme()

# Custom theme with smaller labels and monospace font
ggplot(dat = cars, aes(x = speed, y = dist)) + 
  geom_point() + 
  ggtitle("Vehicle stopping distance vs speed\n") + 
  xlab("\nSpeed (mph)") + 
  ylab("\nStopping distance (ft)") + 
  custom_theme(base_size = 14, base_family = "mono")

emwozniak/reportR documentation built on May 16, 2019, 5:11 a.m.