1. Theme flexibility
In the last video and exercises
2. Ways to use themes
we saw how to fine-tune every part of our plot using the theme layer.
3. Ways to use themes
There are a few other ways of changing theme elements, so let's take a look. We'll begin with defining our own theme layer object.
4. Defining theme objects
If you're using many plots within a presentation or publication, you'll want to have consistency in your style. So, once you settle on a a specific theme, you'll want to apply it to all plots of the same type.
Creating a theme from scratch is a detailed process, that we don't want to repeat for every plot we make.
That's where defining a theme layer object comes into play.
5. Defining theme objects
To see how this works let's return to a plot we've already seen in the last video.
For convenience, we're going to save this plot as an object called Z.
6. Defining theme objects
We can adjust specific theme arguments to get the desired plot style. Here, I've changed the font family, size and title color.
7. Defining theme objects
The first method in automating this process is to save our layer as an object. Here we're just going to call it theme iris.
8. Reusing theme objects
Just as we've seen throughout the course, we can add individual layers to any ggplot object.
This means we can reuse this style over and over. Let's see what happens when we try to apply our new theme object on another plot.
9. Reusing theme objects
Remember this histogram of the iris Sepal widths?
10. Reusing theme objects
Now it has the same style as our scatter plot, without having to retype the whole theme layer.
11. Reusing theme objects
But let's say that on occasion I wanted to modify some other specific elements of a plot. Not a problem, we can just add a another theme layer which will override any previous settings. In this example, I've removed the x axis line.
12. Ways to use themes
So far we just used our theme as an object itself. This is a pretty flexible way of working with theme, but a third way of working with themes is accessing the built-in theme templates.
13. Using built-in themes
Built-in theme functions begin with theme_*. theme classic is my go-to template for great publication-quality plots.
14. Using built-in themes
Of course we can always modify any specific element, as we've already seen.
15. Ways to use themes
There are also packages with pre-defined themes, like the ggthemes package.
16. The ggthemes package
The tufte theme mimics Tufte's classic style, which removes all non-data ink and sets the font to a serif typeface.
17. Ways to use themes
Finally, we can update and set the default theme
18. Updating themes
Updating is done with the theme_update function.
This function behaves differently from a typical function. This command updates the default theme and saves the current default to the object "original".
19. Updating themes
Now, all plots will automatically have the same theme.
20. Setting themes
We can set a complete theme object, like original, using the theme_set function.
21. Let's practice!
Alright, let's try out these concepts in the exercises. In the next video will bring everything together in a simple case study.