This handout accompanies the workshop given on September 4, 2019 at UGAâ€™s DigiLab in the Main Library. There is some overlap with a blog post I did a couple years ago, but this is the first time this material has been presented in a workshop format. As always, please visit joeystanley.com/r for the latest materials.

As I was preparing a workshop on custom themes in ggplot2, I got a little carried away illustrating all the componenets of the `theme` function. I decided to simplify that portion of the workshop and create this separate handout that just focuses on `theme`. It is not yet finished, but it may be of some help to people (including myself!).

# 1 Data prep and sample plots

First off, letâ€™s load ggplot2 before we get carried away.

``library(ggplot2)``

Iâ€™m going to use similar plots to the ones I used in previous workshops. Iâ€™ve got four different plots because when creating a theme, itâ€™s good to try it out on several kinds of plots to make sure they all integrate well.

## 1.1 Amount of sugar per McDonaldâ€™s category

For some of the workshop, Iâ€™ll work with the McDonaldâ€™s menu items dataset, which you can access from my wesite. To simplify things a little bit, Iâ€™ll take a subsetâ€”just four of the nine categories. To make that subset, Iâ€™ll use the `subset` function.

``````menu <- read.csv("http://joeystanley.com/downloads/menu.csv")
menu_subset <- subset(menu, Category %in% c("Smoothies & Shakes", "Desserts", "Beverages", "Snacks & Sides"))``````

The default plot will just be the distribution of the number of sugars in each of the four remaining categories. For the color, Iâ€™ll use Paul Tolâ€™s themes, which I access using the package `ggthemes`.

``````m <- ggplot(menu_subset, aes(Category, Sugars, fill = Category)) +
geom_boxplot(size = 0.75) +
geom_jitter(color = "gray15") +
ggthemes::scale_fill_ptol()``````

So now, to plot it, all I need to do is call `m`.

``m``