... +
theme_minimal() +
theme(
plot.caption = element_text(size = 8, hjust = 1,
color = "#899499"),
plot.caption.position = "plot",
plot.title = element_text(size = 20,
face = "bold",
color = "#36454F"),
plot.subtitle = element_text(size = 14,
color = "#899499"),
axis.title = element_text(size = 14,
color = "#36454F"),
axis.text = element_text(size = 10,
color = "#899499")
)
Modifying a base theme
1 Introduction
It’s really easy to add a theme to your ggplot — just add + theme_minimal()
or + theme_bw()
(or whatever) to the end of your ggplot
command.
But what if you want to customize the theme? You can do that too! Certainly, ggplot
documentation has a lot of details about what you can do, but here is an example of how to customize the theme.
2 Workflow for customizing a theme
The basic idea is this:
- Add a
theme_*()
(such astheme_minimal()
) to yourggplot
command - Decide what you want to change
- Now add a
theme()
command to yourggplot
command - Specify the changes you want to make in the
theme()
command
Okay, let’s see how this works in practice.
3 Example set of changes to a theme
Suppose that you want to change the fonts throughout the plot. You can do that by adding a theme()
command to your ggplot
command. Consider the following:
If you don’t like the above, you can — of course! — change them in any way you please. This page shows you all the options that are available for the element_text()
function. And, as pointed out above, the theme documentation shows many dozens of opportunities that you have for customizing the look of your plots.
4 Workflow for applying these custom changes
The workflow that you should use is something like this:
- Experiment for a while with the
theme()
command to see what you can do. - When you find something that you like, copy it into your code.
- Save the code in a separate file so that you can use it again later; I copy mine into a text file called
custom_theme_options.txt
. - When you want to use it, copy the code from the text file into your R script.
It’s really not a lot of work to do in order to create a set of plots that will have a unified look.