Description Usage Arguments Value Note Author(s) See Also Examples
This function makes presentation-ready ggplot2 plots when added as a theme to a ggplot2 function call.
1 | custom_theme(base_size, base_family)
|
base_size |
Base font size for the plot. Optional; defaults to 18. |
base_family |
Font family for the plot. Optional; defaults to "serif". |
Returns a theme to stylize a ggplot2 graph.
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.
Erica Wozniak
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")
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.