B.18 Customizing with theme

The labels on the x-axis are tough to see in the previous plot. Let’s rotate them by 90 degrees (angle = 90), right justify (hjust = 1) and center them around the tick mark (vjust = 0.3 looks better than vjust = 0.5) using theme.

Code
ggplot(dg, aes(x = home, 
               y = away, 
               fill = as.character(games))) + 
  geom_tile(color = 'black')+
  theme(axis.text.x = element_text(angle = 90, 
                                   vjust = 0.3, 
                                   hjust = 1))

We’ll discuss theme more in the main text. You can see all the theme options here https://ggplot2.tidyverse.org/reference/theme.html.

Other ways to modify ggplots are listed in the function reference https://ggplot2.tidyverse.org/reference/.