class: center, middle, inverse, title-slide # fine tuning ggplot themes ## a flipbook | made with Xaringan ###
Gina Reynolds ###
--- --- name: themes # Greetings: Themes It may seem just cosmetic, but themes can have a big impact on the look and feel of you final plot. The thematic elements are what first meet the eye. For more information on fine adjustment of thematic elements, have a look at the [taming ggplot themes flipbook](https://evamaerey.github.io/little_flipbooks_library/taming_themes_in_ggplot/taming_ggplot_themes.html#1). First, let's check out how to change the look and feel of your graph with some preset themes. --- class: split-40 count: false .left-panel-themes-rotate[ ```r ggplot(data = gapminder_2002) + aes(x = gdpPercap) + aes(y = lifeExp) + geom_point() + aes(color = continent) + theme_bw() ``` ] .right-panel-themes-rotate[ <img src="themes_files/figure-html/themes_rotate_1_output-1.png" width="100%" /> ] --- class: split-40 count: false .left-panel-themes-rotate[ ```r ggplot(data = gapminder_2002) + aes(x = gdpPercap) + aes(y = lifeExp) + geom_point() + aes(color = continent) + * theme_classic() ``` ] .right-panel-themes-rotate[ <img src="themes_files/figure-html/themes_rotate_2_output-1.png" width="100%" /> ] --- class: split-40 count: false .left-panel-themes-rotate[ ```r ggplot(data = gapminder_2002) + aes(x = gdpPercap) + aes(y = lifeExp) + geom_point() + aes(color = continent) + * theme_gray() ``` ] .right-panel-themes-rotate[ <img src="themes_files/figure-html/themes_rotate_3_output-1.png" width="100%" /> ] --- class: split-40 count: false .left-panel-themes-rotate[ ```r ggplot(data = gapminder_2002) + aes(x = gdpPercap) + aes(y = lifeExp) + geom_point() + aes(color = continent) + * theme_light() ``` ] .right-panel-themes-rotate[ <img src="themes_files/figure-html/themes_rotate_4_output-1.png" width="100%" /> ] --- class: split-40 count: false .left-panel-themes-rotate[ ```r ggplot(data = gapminder_2002) + aes(x = gdpPercap) + aes(y = lifeExp) + geom_point() + aes(color = continent) + * theme_minimal() ``` ] .right-panel-themes-rotate[ <img src="themes_files/figure-html/themes_rotate_5_output-1.png" width="100%" /> ] --- class: split-40 count: false .left-panel-themes-rotate[ ```r ggplot(data = gapminder_2002) + aes(x = gdpPercap) + aes(y = lifeExp) + geom_point() + aes(color = continent) + * theme_void() ``` ] .right-panel-themes-rotate[ <img src="themes_files/figure-html/themes_rotate_6_output-1.png" width="100%" /> ] --- class: split-40 count: false .left-panel-themes-rotate[ ```r ggplot(data = gapminder_2002) + aes(x = gdpPercap) + aes(y = lifeExp) + geom_point() + aes(color = continent) + * theme_light(base_size = 10, base_family = "Times") ``` ] .right-panel-themes-rotate[ <img src="themes_files/figure-html/themes_rotate_7_output-1.png" width="100%" /> ] --- class: split-40 count: false .left-panel-themes-rotate[ ```r ggplot(data = gapminder_2002) + aes(x = gdpPercap) + aes(y = lifeExp) + geom_point() + aes(color = continent) + * theme_classic(base_family = "Rockwell") ``` ] .right-panel-themes-rotate[ <img src="themes_files/figure-html/themes_rotate_8_output-1.png" width="100%" /> ] --- class: split-40 count: false .left-panel-themes-rotate[ ```r ggplot(data = gapminder_2002) + aes(x = gdpPercap) + aes(y = lifeExp) + geom_point() + aes(color = continent) + * theme_dark(base_line_size = 14) ``` ] .right-panel-themes-rotate[ <img src="themes_files/figure-html/themes_rotate_9_output-1.png" width="100%" /> ] --- class: split-40 count: false .left-panel-themes-rotate[ ```r ggplot(data = gapminder_2002) + aes(x = gdpPercap) + aes(y = lifeExp) + geom_point() + aes(color = continent) + * theme_minimal(base_rect_size = 10) ``` ] .right-panel-themes-rotate[ <img src="themes_files/figure-html/themes_rotate_10_output-1.png" width="100%" /> ] <style> .left-panel-themes-rotate { color: #777; width: 49%; height: 92%; float: left; font-size: 80% } .right-panel-themes-rotate { width: 50%; float: right; padding-left: 1%; font-size: 80% } .middle-panel-themes-rotate { width: NA%; float: left; padding-left: 1%; font-size: 80% } </style> --- ## Now we can turn to fine tuning. The theme function almost has a grammar of it's own. It's a bit much. --- # Table of Contents - [Ugly Theme Choices](#uglyplot) - Elements - [Text Elements](#textelements) - [Rectangular Elements](#rectangularelements) - [Line Elements](#lineelements) - More - [Legends](#legend) - [Sundry](#sundry) - [Facets](#facet) - [Preset Themes](#presetthemes) --- # Visual Table of Contents <a href="#uglyplot"><img src="figures/custom_theme.png"width="150" height="150" title=figures/custom_theme.png alt=figures/custom_theme.png></a><a href="#textelements"><img src="figures/text_components.png"width="150" height="150" title=figures/text_components.png alt=figures/text_components.png></a><a href="#rectangularelements"><img src="figures/rect_components.png"width="150" height="150" title=figures/rect_components.png alt=figures/rect_components.png></a><a href="#lineelements"><img src="figures/line_components.png"width="150" height="150" title=figures/line_components.png alt=figures/line_components.png></a> <a href="#legend"><img src="figures/legend.png"width="150" height="150" title=figures/legend.png alt=figures/legend.png></a><a href="#sundry"><img src="figures/sundries.png"width="150" height="150" title=figures/sundries.png alt=figures/sundries.png></a><a href="#facet"><img src="figures/small_multiples.png"width="150" height="150" title=figures/small_multiples.png alt=figures/small_multiples.png></a><a href="#presetthemes"><img src="figures/theme_presets.png"width="150" height="150" title=figures/theme_presets.png alt=figures/theme_presets.png></a> --- # Before we begin This resource is focused on fine tuning and communicating what code gives what output. Also, load some libraries: ```r options(scipen = 10) # adjust when scientific notation turns on library(tidyverse) library(gapminder) ``` --- # Base Plot We'll work with the plot below to apply all the theme adjustments. In the next slide, we'll build this plot and save it as the plot object `g`. To this plot object we'll add the theme statements. You might check out [The Tidyverse in Action](https://evamaerey.github.io/tidyverse_in_action/tidyverse_in_action.html) if you are puzzled about how to build `g`. The [ggplot2 Cheatsheet](https://www.rstudio.com/wp-content/uploads/2015/03/ggplot2-cheatsheet.pdf) is also an excellent resource. --- class: split-40 count: false .left-panel-the_plot-auto[ ```r *gapminder ``` ] .right-panel-the_plot-auto[ ``` # A tibble: 1,704 x 6 country continent year lifeExp pop gdpPercap <fct> <fct> <int> <dbl> <int> <dbl> 1 Afghanistan Asia 1952 28.8 8425333 779. 2 Afghanistan Asia 1957 30.3 9240934 821. 3 Afghanistan Asia 1962 32.0 10267083 853. 4 Afghanistan Asia 1967 34.0 11537966 836. 5 Afghanistan Asia 1972 36.1 13079460 740. 6 Afghanistan Asia 1977 38.4 14880372 786. 7 Afghanistan Asia 1982 39.9 12881816 978. 8 Afghanistan Asia 1987 40.8 13867957 852. 9 Afghanistan Asia 1992 41.7 16317921 649. 10 Afghanistan Asia 1997 41.8 22227415 635. # … with 1,694 more rows ``` ] --- class: split-40 count: false .left-panel-the_plot-auto[ ```r gapminder %>% * filter(year == 1992) ``` ] .right-panel-the_plot-auto[ ``` # A tibble: 142 x 6 country continent year lifeExp pop gdpPercap <fct> <fct> <int> <dbl> <int> <dbl> 1 Afghanistan Asia 1992 41.7 16317921 649. 2 Albania Europe 1992 71.6 3326498 2497. 3 Algeria Africa 1992 67.7 26298373 5023. 4 Angola Africa 1992 40.6 8735988 2628. 5 Argentina Americas 1992 71.9 33958947 9308. 6 Australia Oceania 1992 77.6 17481977 23425. 7 Austria Europe 1992 76.0 7914969 27042. 8 Bahrain Asia 1992 72.6 529491 19036. 9 Bangladesh Asia 1992 56.0 113704579 838. 10 Belgium Europe 1992 76.5 10045622 25576. # … with 132 more rows ``` ] --- class: split-40 count: false .left-panel-the_plot-auto[ ```r gapminder %>% filter(year == 1992) %>% * ggplot() ``` ] .right-panel-the_plot-auto[ <img src="themes_files/figure-html/the_plot_auto_3_output-1.png" width="100%" /> ] --- class: split-40 count: false .left-panel-the_plot-auto[ ```r gapminder %>% filter(year == 1992) %>% ggplot() + * aes(x = gdpPercap, y = lifeExp) ``` ] .right-panel-the_plot-auto[ <img src="themes_files/figure-html/the_plot_auto_4_output-1.png" width="100%" /> ] --- class: split-40 count: false .left-panel-the_plot-auto[ ```r gapminder %>% filter(year == 1992) %>% ggplot() + aes(x = gdpPercap, y = lifeExp) + * geom_point(alpha = .8, shape = 21, * fill = "white") ``` ] .right-panel-the_plot-auto[ <img src="themes_files/figure-html/the_plot_auto_5_output-1.png" width="100%" /> ] --- class: split-40 count: false .left-panel-the_plot-auto[ ```r gapminder %>% filter(year == 1992) %>% ggplot() + aes(x = gdpPercap, y = lifeExp) + geom_point(alpha = .8, shape = 21, fill = "white") + * aes(col = continent, fill = continent) ``` ] .right-panel-the_plot-auto[ <img src="themes_files/figure-html/the_plot_auto_6_output-1.png" width="100%" /> ] --- class: split-40 count: false .left-panel-the_plot-auto[ ```r gapminder %>% filter(year == 1992) %>% ggplot() + aes(x = gdpPercap, y = lifeExp) + geom_point(alpha = .8, shape = 21, fill = "white") + aes(col = continent, fill = continent) + * geom_point(alpha = .3, shape = 21) ``` ] .right-panel-the_plot-auto[ <img src="themes_files/figure-html/the_plot_auto_7_output-1.png" width="100%" /> ] --- class: split-40 count: false .left-panel-the_plot-auto[ ```r gapminder %>% filter(year == 1992) %>% ggplot() + aes(x = gdpPercap, y = lifeExp) + geom_point(alpha = .8, shape = 21, fill = "white") + aes(col = continent, fill = continent) + geom_point(alpha = .3, shape = 21) + * aes(size = pop) ``` ] .right-panel-the_plot-auto[ <img src="themes_files/figure-html/the_plot_auto_8_output-1.png" width="100%" /> ] --- class: split-40 count: false .left-panel-the_plot-auto[ ```r gapminder %>% filter(year == 1992) %>% ggplot() + aes(x = gdpPercap, y = lifeExp) + geom_point(alpha = .8, shape = 21, fill = "white") + aes(col = continent, fill = continent) + geom_point(alpha = .3, shape = 21) + aes(size = pop) + * scale_size(guide = F) ``` ] .right-panel-the_plot-auto[ <img src="themes_files/figure-html/the_plot_auto_9_output-1.png" width="100%" /> ] --- class: split-40 count: false .left-panel-the_plot-auto[ ```r gapminder %>% filter(year == 1992) %>% ggplot() + aes(x = gdpPercap, y = lifeExp) + geom_point(alpha = .8, shape = 21, fill = "white") + aes(col = continent, fill = continent) + geom_point(alpha = .3, shape = 21) + aes(size = pop) + scale_size(guide = F) + * labs(title = "Wealth and expected longevity\n in 1992") ``` ] .right-panel-the_plot-auto[ <img src="themes_files/figure-html/the_plot_auto_10_output-1.png" width="100%" /> ] --- class: split-40 count: false .left-panel-the_plot-auto[ ```r gapminder %>% filter(year == 1992) %>% ggplot() + aes(x = gdpPercap, y = lifeExp) + geom_point(alpha = .8, shape = 21, fill = "white") + aes(col = continent, fill = continent) + geom_point(alpha = .3, shape = 21) + aes(size = pop) + scale_size(guide = F) + labs(title = "Wealth and expected longevity\n in 1992") + * labs(subtitle = "Data from gapminder package in R") ``` ] .right-panel-the_plot-auto[ <img src="themes_files/figure-html/the_plot_auto_11_output-1.png" width="100%" /> ] --- class: split-40 count: false .left-panel-the_plot-auto[ ```r gapminder %>% filter(year == 1992) %>% ggplot() + aes(x = gdpPercap, y = lifeExp) + geom_point(alpha = .8, shape = 21, fill = "white") + aes(col = continent, fill = continent) + geom_point(alpha = .3, shape = 21) + aes(size = pop) + scale_size(guide = F) + labs(title = "Wealth and expected longevity\n in 1992") + labs(subtitle = "Data from gapminder package in R") + * labs(x = "GDP per Capita") ``` ] .right-panel-the_plot-auto[ <img src="themes_files/figure-html/the_plot_auto_12_output-1.png" width="100%" /> ] --- class: split-40 count: false .left-panel-the_plot-auto[ ```r gapminder %>% filter(year == 1992) %>% ggplot() + aes(x = gdpPercap, y = lifeExp) + geom_point(alpha = .8, shape = 21, fill = "white") + aes(col = continent, fill = continent) + geom_point(alpha = .3, shape = 21) + aes(size = pop) + scale_size(guide = F) + labs(title = "Wealth and expected longevity\n in 1992") + labs(subtitle = "Data from gapminder package in R") + labs(x = "GDP per Capita") + * labs(y = "Life Expectency") # a tag is also an option ``` ] .right-panel-the_plot-auto[ <img src="themes_files/figure-html/the_plot_auto_13_output-1.png" width="100%" /> ] --- class: split-40 count: false .left-panel-the_plot-auto[ ```r gapminder %>% filter(year == 1992) %>% ggplot() + aes(x = gdpPercap, y = lifeExp) + geom_point(alpha = .8, shape = 21, fill = "white") + aes(col = continent, fill = continent) + geom_point(alpha = .3, shape = 21) + aes(size = pop) + scale_size(guide = F) + labs(title = "Wealth and expected longevity\n in 1992") + labs(subtitle = "Data from gapminder package in R") + labs(x = "GDP per Capita") + labs(y = "Life Expectency") + # a tag is also an option * labs(col = "Continent", fill = "Continent") ``` ] .right-panel-the_plot-auto[ <img src="themes_files/figure-html/the_plot_auto_14_output-1.png" width="100%" /> ] --- class: split-40 count: false .left-panel-the_plot-auto[ ```r gapminder %>% filter(year == 1992) %>% ggplot() + aes(x = gdpPercap, y = lifeExp) + geom_point(alpha = .8, shape = 21, fill = "white") + aes(col = continent, fill = continent) + geom_point(alpha = .3, shape = 21) + aes(size = pop) + scale_size(guide = F) + labs(title = "Wealth and expected longevity\n in 1992") + labs(subtitle = "Data from gapminder package in R") + labs(x = "GDP per Capita") + labs(y = "Life Expectency") + # a tag is also an option labs(col = "Continent", fill = "Continent") + * labs(caption = "Vis: @EvaMaeRey with ggplot") ``` ] .right-panel-the_plot-auto[ <img src="themes_files/figure-html/the_plot_auto_15_output-1.png" width="100%" /> ] --- class: split-40 count: false .left-panel-the_plot-auto[ ```r gapminder %>% filter(year == 1992) %>% ggplot() + aes(x = gdpPercap, y = lifeExp) + geom_point(alpha = .8, shape = 21, fill = "white") + aes(col = continent, fill = continent) + geom_point(alpha = .3, shape = 21) + aes(size = pop) + scale_size(guide = F) + labs(title = "Wealth and expected longevity\n in 1992") + labs(subtitle = "Data from gapminder package in R") + labs(x = "GDP per Capita") + labs(y = "Life Expectency") + # a tag is also an option labs(col = "Continent", fill = "Continent") + labs(caption = "Vis: @EvaMaeRey with ggplot") -> *g ``` ] .right-panel-the_plot-auto[ ] <style> .left-panel-the_plot-auto { color: #777; width: 49%; height: 92%; float: left; font-size: 80% } .right-panel-the_plot-auto { width: 50%; float: right; padding-left: 1%; font-size: 80% } .middle-panel-the_plot-auto { width: NA%; float: left; padding-left: 1%; font-size: 80% } </style> --- # Thematic adjustment overview -- ## Components The components in a ggplot graph are usually things you can point to on a plot. For example the *legend box*, or the *y axis title*, or the *plot title*. -- ## Elements These components have a variety of elements. For example the legend box has the perimeter of the box (the line) and it has the area of the box associated with it. To "point" to specify the element parts of the components, functions like element_line(), element_rect(), and element_text() are used. To delete an entire component, element_blank() can be used. -- ## Aesthetics Aesthetics assignment for theme elements are similar to those available for geometric shapes in the plot. Aesthetics include color, size, line_type, and so on. --- # Graph Components So, what components can be adjusted? (there are lots!) > aspect.ratio > axis.title, axis.title.x, axis.title.x.top, axis.title.x.bottom, axis.title.y, axis.title.y.left, axis.title.y.right, axis.text, axis.text.x, axis.text.x.top, axis.text.x.bottom, axis.text.y, axis.text.y.left, axis.text.y.right, axis.ticks, axis.ticks.x, axis.ticks.x.top, axis.ticks.x.bottom, axis.ticks.y, axis.ticks.y.left, axis.ticks.y.right, axis.ticks.length, axis.line, axis.line.x, axis.line.x.top, axis.line.x.bottom, axis.line.y, axis.line.y.left, axis.line.y.right > legend.background, legend.margin, legend.spacing, legend.spacing.x, legend.spacing.y, legend.key, legend.key.size, legend.key.height, legend.key.width, legend.text, legend.text.align, legend.title, legend.title.align, legend.position, legend.direction, legend.justification, legend.box, legend.box.just, legend.box.margin, legend.box.background, legend.box.spacing > panel.background, panel.border, panel.spacing, panel.spacing.x, panel.spacing.y, panel.grid, panel.grid.major, panel.grid.minor, panel.grid.major.x, panel.grid.major.y, panel.grid.minor.x, panel.grid.minor.y, panel.ontop > plot.background, plot.title, plot.subtitle, plot.caption, plot.tag, plot.tag.position, plot.margin > strip.background, strip.background.x, strip.background.y, strip.placement, strip.text, strip.text.x, strip.text.y, strip.switch.pad.grid, strip.switch.pad.wrap --- name: uglyplot # An ugly plot, for locating components! Now we'll create this plot to get a sense of how thematic modifications can be made, by 1) specifying the component to be adjusted 2) the element of the component to be adjusted and 3) indicating the aesthetic adjustment. The adjustments made should make clear what components of the plot are called in ggplot. Later we'll walk through a more focused adjustments. We'll go through time elements one at at time: text, rectangular, line, etc. <img src="themes_files/figure-html/custom_theme-1.png" width="50%" /> --- class: split-40 count: false .left-panel-custom_theme-auto[ ```r *g ``` ] .right-panel-custom_theme-auto[ <img src="themes_files/figure-html/custom_theme_auto_1_output-1.png" width="100%" /> ] --- class: split-40 count: false .left-panel-custom_theme-auto[ ```r g + * theme(rect = element_rect(fill = "snow3")) ``` ] .right-panel-custom_theme-auto[ <img src="themes_files/figure-html/custom_theme_auto_2_output-1.png" width="100%" /> ] --- class: split-40 count: false .left-panel-custom_theme-auto[ ```r g + theme(rect = element_rect(fill = "snow3")) + * theme(text = element_text(family = "Times New Roman")) ``` ] .right-panel-custom_theme-auto[ <img src="themes_files/figure-html/custom_theme_auto_3_output-1.png" width="100%" /> ] --- class: split-40 count: false .left-panel-custom_theme-auto[ ```r g + theme(rect = element_rect(fill = "snow3")) + theme(text = element_text(family = "Times New Roman")) + * theme(axis.title = element_text(color = "slateblue4")) ``` ] .right-panel-custom_theme-auto[ <img src="themes_files/figure-html/custom_theme_auto_4_output-1.png" width="100%" /> ] --- class: split-40 count: false .left-panel-custom_theme-auto[ ```r g + theme(rect = element_rect(fill = "snow3")) + theme(text = element_text(family = "Times New Roman")) + theme(axis.title = element_text(color = "slateblue4")) + * theme(title = element_text(color = "seagreen")) ``` ] .right-panel-custom_theme-auto[ <img src="themes_files/figure-html/custom_theme_auto_5_output-1.png" width="100%" /> ] --- class: split-40 count: false .left-panel-custom_theme-auto[ ```r g + theme(rect = element_rect(fill = "snow3")) + theme(text = element_text(family = "Times New Roman")) + theme(axis.title = element_text(color = "slateblue4")) + theme(title = element_text(color = "seagreen")) + * theme(axis.line = element_line(color = "orange")) ``` ] .right-panel-custom_theme-auto[ <img src="themes_files/figure-html/custom_theme_auto_6_output-1.png" width="100%" /> ] --- class: split-40 count: false .left-panel-custom_theme-auto[ ```r g + theme(rect = element_rect(fill = "snow3")) + theme(text = element_text(family = "Times New Roman")) + theme(axis.title = element_text(color = "slateblue4")) + theme(title = element_text(color = "seagreen")) + theme(axis.line = element_line(color = "orange")) + * theme(legend.key = element_rect(fill = "violet")) ``` ] .right-panel-custom_theme-auto[ <img src="themes_files/figure-html/custom_theme_auto_7_output-1.png" width="100%" /> ] --- class: split-40 count: false .left-panel-custom_theme-auto[ ```r g + theme(rect = element_rect(fill = "snow3")) + theme(text = element_text(family = "Times New Roman")) + theme(axis.title = element_text(color = "slateblue4")) + theme(title = element_text(color = "seagreen")) + theme(axis.line = element_line(color = "orange")) + theme(legend.key = element_rect(fill = "violet")) + * theme(axis.ticks = element_line(color = "blue")) ``` ] .right-panel-custom_theme-auto[ <img src="themes_files/figure-html/custom_theme_auto_8_output-1.png" width="100%" /> ] --- class: split-40 count: false .left-panel-custom_theme-auto[ ```r g + theme(rect = element_rect(fill = "snow3")) + theme(text = element_text(family = "Times New Roman")) + theme(axis.title = element_text(color = "slateblue4")) + theme(title = element_text(color = "seagreen")) + theme(axis.line = element_line(color = "orange")) + theme(legend.key = element_rect(fill = "violet")) + theme(axis.ticks = element_line(color = "blue")) + * theme(axis.ticks.x = element_blank()) ``` ] .right-panel-custom_theme-auto[ <img src="themes_files/figure-html/custom_theme_auto_9_output-1.png" width="100%" /> ] --- class: split-40 count: false .left-panel-custom_theme-auto[ ```r g + theme(rect = element_rect(fill = "snow3")) + theme(text = element_text(family = "Times New Roman")) + theme(axis.title = element_text(color = "slateblue4")) + theme(title = element_text(color = "seagreen")) + theme(axis.line = element_line(color = "orange")) + theme(legend.key = element_rect(fill = "violet")) + theme(axis.ticks = element_line(color = "blue")) + theme(axis.ticks.x = element_blank()) + * theme(panel.background = element_rect(fill = "steelblue")) ``` ] .right-panel-custom_theme-auto[ <img src="themes_files/figure-html/custom_theme_auto_10_output-1.png" width="100%" /> ] --- class: split-40 count: false .left-panel-custom_theme-auto[ ```r g + theme(rect = element_rect(fill = "snow3")) + theme(text = element_text(family = "Times New Roman")) + theme(axis.title = element_text(color = "slateblue4")) + theme(title = element_text(color = "seagreen")) + theme(axis.line = element_line(color = "orange")) + theme(legend.key = element_rect(fill = "violet")) + theme(axis.ticks = element_line(color = "blue")) + theme(axis.ticks.x = element_blank()) + theme(panel.background = element_rect(fill = "steelblue")) + * theme(panel.grid = * element_line(size = 3, color = "thistle1")) ``` ] .right-panel-custom_theme-auto[ <img src="themes_files/figure-html/custom_theme_auto_11_output-1.png" width="100%" /> ] --- class: split-40 count: false .left-panel-custom_theme-auto[ ```r g + theme(rect = element_rect(fill = "snow3")) + theme(text = element_text(family = "Times New Roman")) + theme(axis.title = element_text(color = "slateblue4")) + theme(title = element_text(color = "seagreen")) + theme(axis.line = element_line(color = "orange")) + theme(legend.key = element_rect(fill = "violet")) + theme(axis.ticks = element_line(color = "blue")) + theme(axis.ticks.x = element_blank()) + theme(panel.background = element_rect(fill = "steelblue")) + theme(panel.grid = element_line(size = 3, color = "thistle1")) + * theme(legend.background = element_rect(fill = "goldenrod1")) ``` ] .right-panel-custom_theme-auto[ <img src="themes_files/figure-html/custom_theme_auto_12_output-1.png" width="100%" /> ] --- class: split-40 count: false .left-panel-custom_theme-auto[ ```r g + theme(rect = element_rect(fill = "snow3")) + theme(text = element_text(family = "Times New Roman")) + theme(axis.title = element_text(color = "slateblue4")) + theme(title = element_text(color = "seagreen")) + theme(axis.line = element_line(color = "orange")) + theme(legend.key = element_rect(fill = "violet")) + theme(axis.ticks = element_line(color = "blue")) + theme(axis.ticks.x = element_blank()) + theme(panel.background = element_rect(fill = "steelblue")) + theme(panel.grid = element_line(size = 3, color = "thistle1")) + theme(legend.background = element_rect(fill = "goldenrod1")) + * theme(legend.text = element_text(size = 7)) ``` ] .right-panel-custom_theme-auto[ <img src="themes_files/figure-html/custom_theme_auto_13_output-1.png" width="100%" /> ] --- class: split-40 count: false .left-panel-custom_theme-auto[ ```r g + theme(rect = element_rect(fill = "snow3")) + theme(text = element_text(family = "Times New Roman")) + theme(axis.title = element_text(color = "slateblue4")) + theme(title = element_text(color = "seagreen")) + theme(axis.line = element_line(color = "orange")) + theme(legend.key = element_rect(fill = "violet")) + theme(axis.ticks = element_line(color = "blue")) + theme(axis.ticks.x = element_blank()) + theme(panel.background = element_rect(fill = "steelblue")) + theme(panel.grid = element_line(size = 3, color = "thistle1")) + theme(legend.background = element_rect(fill = "goldenrod1")) + theme(legend.text = element_text(size = 7)) + * theme(legend.position = "bottom") ``` ] .right-panel-custom_theme-auto[ <img src="themes_files/figure-html/custom_theme_auto_14_output-1.png" width="100%" /> ] --- class: split-40 count: false .left-panel-custom_theme-auto[ ```r g + theme(rect = element_rect(fill = "snow3")) + theme(text = element_text(family = "Times New Roman")) + theme(axis.title = element_text(color = "slateblue4")) + theme(title = element_text(color = "seagreen")) + theme(axis.line = element_line(color = "orange")) + theme(legend.key = element_rect(fill = "violet")) + theme(axis.ticks = element_line(color = "blue")) + theme(axis.ticks.x = element_blank()) + theme(panel.background = element_rect(fill = "steelblue")) + theme(panel.grid = element_line(size = 3, color = "thistle1")) + theme(legend.background = element_rect(fill = "goldenrod1")) + theme(legend.text = element_text(size = 7)) + theme(legend.position = "bottom") + * theme(legend.margin = margin(t = 0, r = 20, * b = 0, l = 40, unit = "pt")) ``` ] .right-panel-custom_theme-auto[ <img src="themes_files/figure-html/custom_theme_auto_15_output-1.png" width="100%" /> ] --- class: split-40 count: false .left-panel-custom_theme-auto[ ```r g + theme(rect = element_rect(fill = "snow3")) + theme(text = element_text(family = "Times New Roman")) + theme(axis.title = element_text(color = "slateblue4")) + theme(title = element_text(color = "seagreen")) + theme(axis.line = element_line(color = "orange")) + theme(legend.key = element_rect(fill = "violet")) + theme(axis.ticks = element_line(color = "blue")) + theme(axis.ticks.x = element_blank()) + theme(panel.background = element_rect(fill = "steelblue")) + theme(panel.grid = element_line(size = 3, color = "thistle1")) + theme(legend.background = element_rect(fill = "goldenrod1")) + theme(legend.text = element_text(size = 7)) + theme(legend.position = "bottom") + theme(legend.margin = margin(t = 0, r = 20, b = 0, l = 40, unit = "pt")) + * theme(aspect.ratio = .5) ``` ] .right-panel-custom_theme-auto[ <img src="themes_files/figure-html/custom_theme_auto_16_output-1.png" width="100%" /> ] <style> .left-panel-custom_theme-auto { color: #777; width: 49%; height: 92%; float: left; font-size: 80% } .right-panel-custom_theme-auto { width: 50%; float: right; padding-left: 1%; font-size: 80% } .middle-panel-custom_theme-auto { width: NA%; float: left; padding-left: 1%; font-size: 80% } </style> --- # What are the elements of these components? Now we'll focus on different elements of the components: - element_line() - element_rect() - element_text() Additionally, element_blank(), allows you to indicate that you don't want the component included in the plot at all. --- # Across-the-board adjustment Across-the-board adjustment to all components with given elements can also be done using the *line*, *rect*, *text*, and *title* adjustments. These will apply generally where no more specific adjustment has been made. > line > rect > text > title --- name: textelements # Focus on text elements! <img src="themes_files/figure-html/text_components-1.png" width="60%" /> --- class: split-40 count: false .left-panel-text_components-auto[ ```r *g ``` ] .right-panel-text_components-auto[ <img src="themes_files/figure-html/text_components_auto_1_output-1.png" width="100%" /> ] --- class: split-40 count: false .left-panel-text_components-auto[ ```r g + * theme(plot.title.position = "plot") ``` ] .right-panel-text_components-auto[ <img src="themes_files/figure-html/text_components_auto_2_output-1.png" width="100%" /> ] --- class: split-40 count: false .left-panel-text_components-auto[ ```r g + theme(plot.title.position = "plot") + * theme(plot.tag = * element_text(color = "plum4", size = 25)) ``` ] .right-panel-text_components-auto[ <img src="themes_files/figure-html/text_components_auto_3_output-1.png" width="100%" /> ] --- class: split-40 count: false .left-panel-text_components-auto[ ```r g + theme(plot.title.position = "plot") + theme(plot.tag = element_text(color = "plum4", size = 25)) + * theme(plot.title = * element_text(color = "plum4", * size = 20, * lineheight = 2.5)) ``` ] .right-panel-text_components-auto[ <img src="themes_files/figure-html/text_components_auto_4_output-1.png" width="100%" /> ] --- class: split-40 count: false .left-panel-text_components-auto[ ```r g + theme(plot.title.position = "plot") + theme(plot.tag = element_text(color = "plum4", size = 25)) + theme(plot.title = element_text(color = "plum4", size = 20, lineheight = 2.5)) + * theme(plot.subtitle = element_text(color = "plum4")) ``` ] .right-panel-text_components-auto[ <img src="themes_files/figure-html/text_components_auto_5_output-1.png" width="100%" /> ] --- class: split-40 count: false .left-panel-text_components-auto[ ```r g + theme(plot.title.position = "plot") + theme(plot.tag = element_text(color = "plum4", size = 25)) + theme(plot.title = element_text(color = "plum4", size = 20, lineheight = 2.5)) + theme(plot.subtitle = element_text(color = "plum4")) + * theme(axis.title.y = * element_text(color = "plum4", * size = rel(3))) ``` ] .right-panel-text_components-auto[ <img src="themes_files/figure-html/text_components_auto_6_output-1.png" width="100%" /> ] --- class: split-40 count: false .left-panel-text_components-auto[ ```r g + theme(plot.title.position = "plot") + theme(plot.tag = element_text(color = "plum4", size = 25)) + theme(plot.title = element_text(color = "plum4", size = 20, lineheight = 2.5)) + theme(plot.subtitle = element_text(color = "plum4")) + theme(axis.title.y = element_text(color = "plum4", size = rel(3))) + * theme(axis.text.y = element_text(color = "plum4")) ``` ] .right-panel-text_components-auto[ <img src="themes_files/figure-html/text_components_auto_7_output-1.png" width="100%" /> ] --- class: split-40 count: false .left-panel-text_components-auto[ ```r g + theme(plot.title.position = "plot") + theme(plot.tag = element_text(color = "plum4", size = 25)) + theme(plot.title = element_text(color = "plum4", size = 20, lineheight = 2.5)) + theme(plot.subtitle = element_text(color = "plum4")) + theme(axis.title.y = element_text(color = "plum4", size = rel(3))) + theme(axis.text.y = element_text(color = "plum4")) + * theme(legend.title = * element_text(color = "plum4", size = 22)) ``` ] .right-panel-text_components-auto[ <img src="themes_files/figure-html/text_components_auto_8_output-1.png" width="100%" /> ] --- class: split-40 count: false .left-panel-text_components-auto[ ```r g + theme(plot.title.position = "plot") + theme(plot.tag = element_text(color = "plum4", size = 25)) + theme(plot.title = element_text(color = "plum4", size = 20, lineheight = 2.5)) + theme(plot.subtitle = element_text(color = "plum4")) + theme(axis.title.y = element_text(color = "plum4", size = rel(3))) + theme(axis.text.y = element_text(color = "plum4")) + theme(legend.title = element_text(color = "plum4", size = 22)) + * theme(legend.text = element_text(color = "plum4")) ``` ] .right-panel-text_components-auto[ <img src="themes_files/figure-html/text_components_auto_9_output-1.png" width="100%" /> ] --- class: split-40 count: false .left-panel-text_components-auto[ ```r g + theme(plot.title.position = "plot") + theme(plot.tag = element_text(color = "plum4", size = 25)) + theme(plot.title = element_text(color = "plum4", size = 20, lineheight = 2.5)) + theme(plot.subtitle = element_text(color = "plum4")) + theme(axis.title.y = element_text(color = "plum4", size = rel(3))) + theme(axis.text.y = element_text(color = "plum4")) + theme(legend.title = element_text(color = "plum4", size = 22)) + theme(legend.text = element_text(color = "plum4")) + * theme(axis.title.x = element_text(color = "plum4")) ``` ] .right-panel-text_components-auto[ <img src="themes_files/figure-html/text_components_auto_10_output-1.png" width="100%" /> ] --- class: split-40 count: false .left-panel-text_components-auto[ ```r g + theme(plot.title.position = "plot") + theme(plot.tag = element_text(color = "plum4", size = 25)) + theme(plot.title = element_text(color = "plum4", size = 20, lineheight = 2.5)) + theme(plot.subtitle = element_text(color = "plum4")) + theme(axis.title.y = element_text(color = "plum4", size = rel(3))) + theme(axis.text.y = element_text(color = "plum4")) + theme(legend.title = element_text(color = "plum4", size = 22)) + theme(legend.text = element_text(color = "plum4")) + theme(axis.title.x = element_text(color = "plum4")) + * theme(axis.text.x = element_text(color = "plum4")) ``` ] .right-panel-text_components-auto[ <img src="themes_files/figure-html/text_components_auto_11_output-1.png" width="100%" /> ] --- class: split-40 count: false .left-panel-text_components-auto[ ```r g + theme(plot.title.position = "plot") + theme(plot.tag = element_text(color = "plum4", size = 25)) + theme(plot.title = element_text(color = "plum4", size = 20, lineheight = 2.5)) + theme(plot.subtitle = element_text(color = "plum4")) + theme(axis.title.y = element_text(color = "plum4", size = rel(3))) + theme(axis.text.y = element_text(color = "plum4")) + theme(legend.title = element_text(color = "plum4", size = 22)) + theme(legend.text = element_text(color = "plum4")) + theme(axis.title.x = element_text(color = "plum4")) + theme(axis.text.x = element_text(color = "plum4")) + * theme(plot.caption = * element_text(color = "plum4", size = 20)) ``` ] .right-panel-text_components-auto[ <img src="themes_files/figure-html/text_components_auto_12_output-1.png" width="100%" /> ] --- class: split-40 count: false .left-panel-text_components-auto[ ```r g + theme(plot.title.position = "plot") + theme(plot.tag = element_text(color = "plum4", size = 25)) + theme(plot.title = element_text(color = "plum4", size = 20, lineheight = 2.5)) + theme(plot.subtitle = element_text(color = "plum4")) + theme(axis.title.y = element_text(color = "plum4", size = rel(3))) + theme(axis.text.y = element_text(color = "plum4")) + theme(legend.title = element_text(color = "plum4", size = 22)) + theme(legend.text = element_text(color = "plum4")) + theme(axis.title.x = element_text(color = "plum4")) + theme(axis.text.x = element_text(color = "plum4")) + theme(plot.caption = element_text(color = "plum4", size = 20)) + * theme(text = element_text(family = "Times")) ``` ] .right-panel-text_components-auto[ <img src="themes_files/figure-html/text_components_auto_13_output-1.png" width="100%" /> ] --- class: split-40 count: false .left-panel-text_components-auto[ ```r g + theme(plot.title.position = "plot") + theme(plot.tag = element_text(color = "plum4", size = 25)) + theme(plot.title = element_text(color = "plum4", size = 20, lineheight = 2.5)) + theme(plot.subtitle = element_text(color = "plum4")) + theme(axis.title.y = element_text(color = "plum4", size = rel(3))) + theme(axis.text.y = element_text(color = "plum4")) + theme(legend.title = element_text(color = "plum4", size = 22)) + theme(legend.text = element_text(color = "plum4")) + theme(axis.title.x = element_text(color = "plum4")) + theme(axis.text.x = element_text(color = "plum4")) + theme(plot.caption = element_text(color = "plum4", size = 20)) + theme(text = element_text(family = "Times")) + * theme(text = element_text(face = "bold.italic")) ``` ] .right-panel-text_components-auto[ <img src="themes_files/figure-html/text_components_auto_14_output-1.png" width="100%" /> ] --- class: split-40 count: false .left-panel-text_components-auto[ ```r g + theme(plot.title.position = "plot") + theme(plot.tag = element_text(color = "plum4", size = 25)) + theme(plot.title = element_text(color = "plum4", size = 20, lineheight = 2.5)) + theme(plot.subtitle = element_text(color = "plum4")) + theme(axis.title.y = element_text(color = "plum4", size = rel(3))) + theme(axis.text.y = element_text(color = "plum4")) + theme(legend.title = element_text(color = "plum4", size = 22)) + theme(legend.text = element_text(color = "plum4")) + theme(axis.title.x = element_text(color = "plum4")) + theme(axis.text.x = element_text(color = "plum4")) + theme(plot.caption = element_text(color = "plum4", size = 20)) + theme(text = element_text(family = "Times")) + theme(text = element_text(face = "bold.italic")) + * theme(text = element_text( * margin = margin(t = 3, r = 3, b = 3, l = 3, * unit = "pt"))) ``` ] .right-panel-text_components-auto[ <img src="themes_files/figure-html/text_components_auto_15_output-1.png" width="100%" /> ] --- class: split-40 count: false .left-panel-text_components-auto[ ```r g + theme(plot.title.position = "plot") + theme(plot.tag = element_text(color = "plum4", size = 25)) + theme(plot.title = element_text(color = "plum4", size = 20, lineheight = 2.5)) + theme(plot.subtitle = element_text(color = "plum4")) + theme(axis.title.y = element_text(color = "plum4", size = rel(3))) + theme(axis.text.y = element_text(color = "plum4")) + theme(legend.title = element_text(color = "plum4", size = 22)) + theme(legend.text = element_text(color = "plum4")) + theme(axis.title.x = element_text(color = "plum4")) + theme(axis.text.x = element_text(color = "plum4")) + theme(plot.caption = element_text(color = "plum4", size = 20)) + theme(text = element_text(family = "Times")) + theme(text = element_text(face = "bold.italic")) + theme(text = element_text( margin = margin(t = 3, r = 3, b = 3, l = 3, unit = "pt"))) + * theme(text = element_text(angle = 2)) ``` ] .right-panel-text_components-auto[ <img src="themes_files/figure-html/text_components_auto_16_output-1.png" width="100%" /> ] --- class: split-40 count: false .left-panel-text_components-auto[ ```r g + theme(plot.title.position = "plot") + theme(plot.tag = element_text(color = "plum4", size = 25)) + theme(plot.title = element_text(color = "plum4", size = 20, lineheight = 2.5)) + theme(plot.subtitle = element_text(color = "plum4")) + theme(axis.title.y = element_text(color = "plum4", size = rel(3))) + theme(axis.text.y = element_text(color = "plum4")) + theme(legend.title = element_text(color = "plum4", size = 22)) + theme(legend.text = element_text(color = "plum4")) + theme(axis.title.x = element_text(color = "plum4")) + theme(axis.text.x = element_text(color = "plum4")) + theme(plot.caption = element_text(color = "plum4", size = 20)) + theme(text = element_text(family = "Times")) + theme(text = element_text(face = "bold.italic")) + theme(text = element_text( margin = margin(t = 3, r = 3, b = 3, l = 3, unit = "pt"))) + theme(text = element_text(angle = 2)) + * theme(plot.title = element_text(hjust = .5)) ``` ] .right-panel-text_components-auto[ <img src="themes_files/figure-html/text_components_auto_17_output-1.png" width="100%" /> ] --- class: split-40 count: false .left-panel-text_components-auto[ ```r g + theme(plot.title.position = "plot") + theme(plot.tag = element_text(color = "plum4", size = 25)) + theme(plot.title = element_text(color = "plum4", size = 20, lineheight = 2.5)) + theme(plot.subtitle = element_text(color = "plum4")) + theme(axis.title.y = element_text(color = "plum4", size = rel(3))) + theme(axis.text.y = element_text(color = "plum4")) + theme(legend.title = element_text(color = "plum4", size = 22)) + theme(legend.text = element_text(color = "plum4")) + theme(axis.title.x = element_text(color = "plum4")) + theme(axis.text.x = element_text(color = "plum4")) + theme(plot.caption = element_text(color = "plum4", size = 20)) + theme(text = element_text(family = "Times")) + theme(text = element_text(face = "bold.italic")) + theme(text = element_text( margin = margin(t = 3, r = 3, b = 3, l = 3, unit = "pt"))) + theme(text = element_text(angle = 2)) + theme(plot.title = element_text(hjust = .5)) + * theme(axis.title.x = element_text(hjust = 1)) ``` ] .right-panel-text_components-auto[ <img src="themes_files/figure-html/text_components_auto_18_output-1.png" width="100%" /> ] <style> .left-panel-text_components-auto { color: #777; width: 49%; height: 92%; float: left; font-size: 80% } .right-panel-text_components-auto { width: 50%; float: right; padding-left: 1%; font-size: 80% } .middle-panel-text_components-auto { width: NA%; float: left; padding-left: 1%; font-size: 80% } </style> --- name: rectangularelements # Focus on rectangular elements! <img src="themes_files/figure-html/rect_components-1.png" width="60%" /> --- class: split-40 count: false .left-panel-rect_components-auto[ ```r *g ``` ] .right-panel-rect_components-auto[ <img src="themes_files/figure-html/rect_components_auto_1_output-1.png" width="100%" /> ] --- class: split-40 count: false .left-panel-rect_components-auto[ ```r g + * theme(plot.background = * element_rect(fill = "purple", * color = "darkolivegreen", * size = 3)) ``` ] .right-panel-rect_components-auto[ <img src="themes_files/figure-html/rect_components_auto_2_output-1.png" width="100%" /> ] --- class: split-40 count: false .left-panel-rect_components-auto[ ```r g + theme(plot.background = element_rect(fill = "purple", color = "darkolivegreen", size = 3)) + * theme(panel.background = * element_rect(fill = "purple", * color = "darkolivegreen", * size = 3)) ``` ] .right-panel-rect_components-auto[ <img src="themes_files/figure-html/rect_components_auto_3_output-1.png" width="100%" /> ] --- class: split-40 count: false .left-panel-rect_components-auto[ ```r g + theme(plot.background = element_rect(fill = "purple", color = "darkolivegreen", size = 3)) + theme(panel.background = element_rect(fill = "purple", color = "darkolivegreen", size = 3)) + * theme(legend.background = * element_rect(fill = "purple", * color = "darkolivegreen", * size = 3)) ``` ] .right-panel-rect_components-auto[ <img src="themes_files/figure-html/rect_components_auto_4_output-1.png" width="100%" /> ] --- class: split-40 count: false .left-panel-rect_components-auto[ ```r g + theme(plot.background = element_rect(fill = "purple", color = "darkolivegreen", size = 3)) + theme(panel.background = element_rect(fill = "purple", color = "darkolivegreen", size = 3)) + theme(legend.background = element_rect(fill = "purple", color = "darkolivegreen", size = 3)) + * theme(legend.key = * element_rect(fill = "purple", * color = "darkolivegreen", * size = 3)) ``` ] .right-panel-rect_components-auto[ <img src="themes_files/figure-html/rect_components_auto_5_output-1.png" width="100%" /> ] --- class: split-40 count: false .left-panel-rect_components-auto[ ```r g + theme(plot.background = element_rect(fill = "purple", color = "darkolivegreen", size = 3)) + theme(panel.background = element_rect(fill = "purple", color = "darkolivegreen", size = 3)) + theme(legend.background = element_rect(fill = "purple", color = "darkolivegreen", size = 3)) + theme(legend.key = element_rect(fill = "purple", color = "darkolivegreen", size = 3)) + * theme(panel.border = * element_rect(color = "magenta", * fill = NA, size = 4)) ``` ] .right-panel-rect_components-auto[ <img src="themes_files/figure-html/rect_components_auto_6_output-1.png" width="100%" /> ] <style> .left-panel-rect_components-auto { color: #777; width: 49%; height: 92%; float: left; font-size: 80% } .right-panel-rect_components-auto { width: 50%; float: right; padding-left: 1%; font-size: 80% } .middle-panel-rect_components-auto { width: NA%; float: left; padding-left: 1%; font-size: 80% } </style> --- name: lineelements # Focus on line elements! <img src="themes_files/figure-html/line_components-1.png" width="60%" /> --- class: split-40 count: false .left-panel-line_components-auto[ ```r *g ``` ] .right-panel-line_components-auto[ <img src="themes_files/figure-html/line_components_auto_1_output-1.png" width="100%" /> ] --- class: split-40 count: false .left-panel-line_components-auto[ ```r g + * theme(axis.ticks.y = * element_line(size = 10, * color = "blue")) ``` ] .right-panel-line_components-auto[ <img src="themes_files/figure-html/line_components_auto_2_output-1.png" width="100%" /> ] --- class: split-40 count: false .left-panel-line_components-auto[ ```r g + theme(axis.ticks.y = element_line(size = 10, color = "blue")) + * theme(axis.ticks.x = * element_line(size = 10, * color = "blue")) ``` ] .right-panel-line_components-auto[ <img src="themes_files/figure-html/line_components_auto_3_output-1.png" width="100%" /> ] --- class: split-40 count: false .left-panel-line_components-auto[ ```r g + theme(axis.ticks.y = element_line(size = 10, color = "blue")) + theme(axis.ticks.x = element_line(size = 10, color = "blue")) + * theme(panel.grid.major.y = * element_line(size = 2, * linetype = "dashed", * color = "blue", * lineend = "round")) ``` ] .right-panel-line_components-auto[ <img src="themes_files/figure-html/line_components_auto_4_output-1.png" width="100%" /> ] --- class: split-40 count: false .left-panel-line_components-auto[ ```r g + theme(axis.ticks.y = element_line(size = 10, color = "blue")) + theme(axis.ticks.x = element_line(size = 10, color = "blue")) + theme(panel.grid.major.y = element_line(size = 2, linetype = "dashed", color = "blue", lineend = "round")) + * theme(panel.grid.major.x = * element_line(size = 2, * arrow = arrow(), * color = "blue", * lineend = "round")) ``` ] .right-panel-line_components-auto[ <img src="themes_files/figure-html/line_components_auto_5_output-1.png" width="100%" /> ] --- class: split-40 count: false .left-panel-line_components-auto[ ```r g + theme(axis.ticks.y = element_line(size = 10, color = "blue")) + theme(axis.ticks.x = element_line(size = 10, color = "blue")) + theme(panel.grid.major.y = element_line(size = 2, linetype = "dashed", color = "blue", lineend = "round")) + theme(panel.grid.major.x = element_line(size = 2, arrow = arrow(), color = "blue", lineend = "round")) + * theme(panel.grid.minor.y = * element_line(size = 1, * linetype = "dotted", * color = "blue", * lineend = "butt")) ``` ] .right-panel-line_components-auto[ <img src="themes_files/figure-html/line_components_auto_6_output-1.png" width="100%" /> ] --- class: split-40 count: false .left-panel-line_components-auto[ ```r g + theme(axis.ticks.y = element_line(size = 10, color = "blue")) + theme(axis.ticks.x = element_line(size = 10, color = "blue")) + theme(panel.grid.major.y = element_line(size = 2, linetype = "dashed", color = "blue", lineend = "round")) + theme(panel.grid.major.x = element_line(size = 2, arrow = arrow(), color = "blue", lineend = "round")) + theme(panel.grid.minor.y = element_line(size = 1, linetype = "dotted", color = "blue", lineend = "butt")) + * theme(panel.grid = * element_line(color = "blue")) ``` ] .right-panel-line_components-auto[ <img src="themes_files/figure-html/line_components_auto_7_output-1.png" width="100%" /> ] --- class: split-40 count: false .left-panel-line_components-auto[ ```r g + theme(axis.ticks.y = element_line(size = 10, color = "blue")) + theme(axis.ticks.x = element_line(size = 10, color = "blue")) + theme(panel.grid.major.y = element_line(size = 2, linetype = "dashed", color = "blue", lineend = "round")) + theme(panel.grid.major.x = element_line(size = 2, arrow = arrow(), color = "blue", lineend = "round")) + theme(panel.grid.minor.y = element_line(size = 1, linetype = "dotted", color = "blue", lineend = "butt")) + theme(panel.grid = element_line(color = "blue")) + * theme(axis.line.x.top = * element_line(size = 2, * color = "blue")) ``` ] .right-panel-line_components-auto[ <img src="themes_files/figure-html/line_components_auto_8_output-1.png" width="100%" /> ] --- class: split-40 count: false .left-panel-line_components-auto[ ```r g + theme(axis.ticks.y = element_line(size = 10, color = "blue")) + theme(axis.ticks.x = element_line(size = 10, color = "blue")) + theme(panel.grid.major.y = element_line(size = 2, linetype = "dashed", color = "blue", lineend = "round")) + theme(panel.grid.major.x = element_line(size = 2, arrow = arrow(), color = "blue", lineend = "round")) + theme(panel.grid.minor.y = element_line(size = 1, linetype = "dotted", color = "blue", lineend = "butt")) + theme(panel.grid = element_line(color = "blue")) + theme(axis.line.x.top = element_line(size = 2, color = "blue")) + * theme(panel.ontop = TRUE, * panel.background = element_blank()) # in front of the data ``` ] .right-panel-line_components-auto[ <img src="themes_files/figure-html/line_components_auto_9_output-1.png" width="100%" /> ] <style> .left-panel-line_components-auto { color: #777; width: 49%; height: 92%; float: left; font-size: 80% } .right-panel-line_components-auto { width: 50%; float: right; padding-left: 1%; font-size: 80% } .middle-panel-line_components-auto { width: NA%; float: left; padding-left: 1%; font-size: 80% } </style> --- # What aesthetics of these elements can be adjusted? | aesthetic | adjustable for element of type: | |-----|----| | fill | *rect* | | color | *rect, line, text* | | size | *rect, line, text* | | linetype | *rect, line* | | lineend | *line* | | arrow | *line* | | family (font) | *text* | | face | *text* | | hjust | *text* | | vjust | *text* | | angle | *text* | | lineheight | *text* | | margin | *text* | | debug | *text* | | inherit.blank | *rect, line, text* | --- name: legends # More legend options! <img src="themes_files/figure-html/legend-1.png" width="60%" /> --- class: split-40 count: false .left-panel-legend-auto[ ```r *g ``` ] .right-panel-legend-auto[ <img src="themes_files/figure-html/legend_auto_1_output-1.png" width="100%" /> ] --- class: split-40 count: false .left-panel-legend-auto[ ```r g + * theme(legend.position = "bottom") ``` ] .right-panel-legend-auto[ <img src="themes_files/figure-html/legend_auto_2_output-1.png" width="100%" /> ] --- class: split-40 count: false .left-panel-legend-auto[ ```r g + theme(legend.position = "bottom") + * theme(legend.position = "none") ``` ] .right-panel-legend-auto[ <img src="themes_files/figure-html/legend_auto_3_output-1.png" width="100%" /> ] --- class: split-40 count: false .left-panel-legend-auto[ ```r g + theme(legend.position = "bottom") + theme(legend.position = "none") + * theme(legend.position = c(.8, .25)) ``` ] .right-panel-legend-auto[ <img src="themes_files/figure-html/legend_auto_4_output-1.png" width="100%" /> ] --- class: split-40 count: false .left-panel-legend-auto[ ```r g + theme(legend.position = "bottom") + theme(legend.position = "none") + theme(legend.position = c(.8, .25)) + * theme(legend.direction = "horizontal") ``` ] .right-panel-legend-auto[ <img src="themes_files/figure-html/legend_auto_5_output-1.png" width="100%" /> ] --- class: split-40 count: false .left-panel-legend-auto[ ```r g + theme(legend.position = "bottom") + theme(legend.position = "none") + theme(legend.position = c(.8, .25)) + theme(legend.direction = "horizontal") + * theme(legend.key = element_rect()) ``` ] .right-panel-legend-auto[ <img src="themes_files/figure-html/legend_auto_6_output-1.png" width="100%" /> ] --- class: split-40 count: false .left-panel-legend-auto[ ```r g + theme(legend.position = "bottom") + theme(legend.position = "none") + theme(legend.position = c(.8, .25)) + theme(legend.direction = "horizontal") + theme(legend.key = element_rect()) + * guides(fill = guide_legend(size = 35)) ``` ] .right-panel-legend-auto[ <img src="themes_files/figure-html/legend_auto_7_output-1.png" width="100%" /> ] <style> .left-panel-legend-auto { color: #777; width: 49%; height: 92%; float: left; font-size: 80% } .right-panel-legend-auto { width: 50%; float: right; padding-left: 1%; font-size: 80% } .middle-panel-legend-auto { width: NA%; float: left; padding-left: 1%; font-size: 80% } </style> --- name: sundries # More modifications! (Sundries) <img src="themes_files/figure-html/sundries-1.png" width="60%" /> --- class: split-40 count: false .left-panel-sundries-auto[ ```r *g ``` ] .right-panel-sundries-auto[ <img src="themes_files/figure-html/sundries_auto_1_output-1.png" width="100%" /> ] --- class: split-40 count: false .left-panel-sundries-auto[ ```r g + * theme(plot.tag.position = "topright") ``` ] .right-panel-sundries-auto[ <img src="themes_files/figure-html/sundries_auto_2_output-1.png" width="100%" /> ] --- class: split-40 count: false .left-panel-sundries-auto[ ```r g + theme(plot.tag.position = "topright") + * scale_color_discrete(guide = FALSE) ``` ] .right-panel-sundries-auto[ <img src="themes_files/figure-html/sundries_auto_3_output-1.png" width="100%" /> ] --- class: split-40 count: false .left-panel-sundries-auto[ ```r g + theme(plot.tag.position = "topright") + scale_color_discrete(guide = FALSE) + * scale_fill_discrete(guide = FALSE) ``` ] .right-panel-sundries-auto[ <img src="themes_files/figure-html/sundries_auto_4_output-1.png" width="100%" /> ] --- class: split-40 count: false .left-panel-sundries-auto[ ```r g + theme(plot.tag.position = "topright") + scale_color_discrete(guide = FALSE) + scale_fill_discrete(guide = FALSE) + * scale_x_continuous(position = "top") ``` ] .right-panel-sundries-auto[ <img src="themes_files/figure-html/sundries_auto_5_output-1.png" width="100%" /> ] --- class: split-40 count: false .left-panel-sundries-auto[ ```r g + theme(plot.tag.position = "topright") + scale_color_discrete(guide = FALSE) + scale_fill_discrete(guide = FALSE) + scale_x_continuous(position = "top") + * scale_y_continuous(position = "right") ``` ] .right-panel-sundries-auto[ <img src="themes_files/figure-html/sundries_auto_6_output-1.png" width="100%" /> ] --- class: split-40 count: false .left-panel-sundries-auto[ ```r g + theme(plot.tag.position = "topright") + scale_color_discrete(guide = FALSE) + scale_fill_discrete(guide = FALSE) + scale_x_continuous(position = "top") + scale_y_continuous(position = "right") + * theme(aspect.ratio = .5) ``` ] .right-panel-sundries-auto[ <img src="themes_files/figure-html/sundries_auto_7_output-1.png" width="100%" /> ] <style> .left-panel-sundries-auto { color: #777; width: 49%; height: 92%; float: left; font-size: 80% } .right-panel-sundries-auto { width: 50%; float: right; padding-left: 1%; font-size: 80% } .middle-panel-sundries-auto { width: NA%; float: left; padding-left: 1%; font-size: 80% } </style> --- name: facet # Focus on facet elements! <img src="themes_files/figure-html/small_multiples-1.png" width="60%" /> --- class: split-40 count: false .left-panel-small_multiples-auto[ ```r *g ``` ] .right-panel-small_multiples-auto[ <img src="themes_files/figure-html/small_multiples_auto_1_output-1.png" width="100%" /> ] --- class: split-40 count: false .left-panel-small_multiples-auto[ ```r g + * facet_wrap(~ continent, * strip.position = "right") ``` ] .right-panel-small_multiples-auto[ <img src="themes_files/figure-html/small_multiples_auto_2_output-1.png" width="100%" /> ] --- class: split-40 count: false .left-panel-small_multiples-auto[ ```r g + facet_wrap(~ continent, strip.position = "right") + * theme(strip.background = * element_rect(fill = "pink")) ``` ] .right-panel-small_multiples-auto[ <img src="themes_files/figure-html/small_multiples_auto_3_output-1.png" width="100%" /> ] --- class: split-40 count: false .left-panel-small_multiples-auto[ ```r g + facet_wrap(~ continent, strip.position = "right") + theme(strip.background = element_rect(fill = "pink")) + * theme(strip.text.y = * element_text(color = "snow", size = 12)) ``` ] .right-panel-small_multiples-auto[ <img src="themes_files/figure-html/small_multiples_auto_4_output-1.png" width="100%" /> ] --- class: split-40 count: false .left-panel-small_multiples-auto[ ```r g + facet_wrap(~ continent, strip.position = "right") + theme(strip.background = element_rect(fill = "pink")) + theme(strip.text.y = element_text(color = "snow", size = 12)) + * theme(strip.text.y = * element_text(angle = -80)) ``` ] .right-panel-small_multiples-auto[ <img src="themes_files/figure-html/small_multiples_auto_5_output-1.png" width="100%" /> ] --- class: split-40 count: false .left-panel-small_multiples-auto[ ```r g + facet_wrap(~ continent, strip.position = "right") + theme(strip.background = element_rect(fill = "pink")) + theme(strip.text.y = element_text(color = "snow", size = 12)) + theme(strip.text.y = element_text(angle = -80)) + * theme(panel.spacing.x = * unit(1.5, "lines")) ``` ] .right-panel-small_multiples-auto[ <img src="themes_files/figure-html/small_multiples_auto_6_output-1.png" width="100%" /> ] --- class: split-40 count: false .left-panel-small_multiples-auto[ ```r g + facet_wrap(~ continent, strip.position = "right") + theme(strip.background = element_rect(fill = "pink")) + theme(strip.text.y = element_text(color = "snow", size = 12)) + theme(strip.text.y = element_text(angle = -80)) + theme(panel.spacing.x = unit(1.5, "lines")) + * theme(panel.spacing.y = * unit(2, "lines")) ``` ] .right-panel-small_multiples-auto[ <img src="themes_files/figure-html/small_multiples_auto_7_output-1.png" width="100%" /> ] --- class: split-40 count: false .left-panel-small_multiples-auto[ ```r g + facet_wrap(~ continent, strip.position = "right") + theme(strip.background = element_rect(fill = "pink")) + theme(strip.text.y = element_text(color = "snow", size = 12)) + theme(strip.text.y = element_text(angle = -80)) + theme(panel.spacing.x = unit(1.5, "lines")) + theme(panel.spacing.y = unit(2, "lines")) + * theme(strip.switch.pad.grid = * unit(0, "cm")) ``` ] .right-panel-small_multiples-auto[ <img src="themes_files/figure-html/small_multiples_auto_8_output-1.png" width="100%" /> ] <style> .left-panel-small_multiples-auto { color: #777; width: 49%; height: 92%; float: left; font-size: 80% } .right-panel-small_multiples-auto { width: 50%; float: right; padding-left: 1%; font-size: 80% } .middle-panel-small_multiples-auto { width: NA%; float: left; padding-left: 1%; font-size: 80% } </style> --- After you are done fine-tuning you might be interested in saving your thematic choices. Theme choices can be bundled in a theme set statement and then subsequent plots will hold onto those choices and apply them in subsequent plot. https://ggplot2.tidyverse.org/reference/theme_get.html --- class: split-40 count: false .left-panel-bundle-auto[ ```r *my_theme <- function(){ * theme(rect = element_rect(fill = "snow3")) + * theme(text = element_text(family = "Times New Roman")) + * theme(axis.title = element_text(color = "slateblue4")) + * theme(title = element_text(color = "seagreen")) + * theme(axis.line = element_line(color = "orange")) *} ``` ] .right-panel-bundle-auto[ ] --- class: split-40 count: false .left-panel-bundle-auto[ ```r my_theme <- function(){ theme(rect = element_rect(fill = "snow3")) + theme(text = element_text(family = "Times New Roman")) + theme(axis.title = element_text(color = "slateblue4")) + theme(title = element_text(color = "seagreen")) + theme(axis.line = element_line(color = "orange")) } *cars ``` ] .right-panel-bundle-auto[ ``` speed dist 1 4 2 2 4 10 3 7 4 4 7 22 5 8 16 6 9 10 7 10 18 8 10 26 9 10 34 10 11 17 11 11 28 12 12 14 13 12 20 14 12 24 15 12 28 16 13 26 17 13 34 18 13 34 19 13 46 20 14 26 21 14 36 22 14 60 23 14 80 24 15 20 25 15 26 26 15 54 27 16 32 28 16 40 29 17 32 30 17 40 31 17 50 32 18 42 33 18 56 34 18 76 35 18 84 36 19 36 37 19 46 38 19 68 39 20 32 40 20 48 41 20 52 42 20 56 43 20 64 44 22 66 45 23 54 46 24 70 47 24 92 48 24 93 49 24 120 50 25 85 ``` ] --- class: split-40 count: false .left-panel-bundle-auto[ ```r my_theme <- function(){ theme(rect = element_rect(fill = "snow3")) + theme(text = element_text(family = "Times New Roman")) + theme(axis.title = element_text(color = "slateblue4")) + theme(title = element_text(color = "seagreen")) + theme(axis.line = element_line(color = "orange")) } cars %>% * ggplot() ``` ] .right-panel-bundle-auto[ <img src="themes_files/figure-html/bundle_auto_3_output-1.png" width="100%" /> ] --- class: split-40 count: false .left-panel-bundle-auto[ ```r my_theme <- function(){ theme(rect = element_rect(fill = "snow3")) + theme(text = element_text(family = "Times New Roman")) + theme(axis.title = element_text(color = "slateblue4")) + theme(title = element_text(color = "seagreen")) + theme(axis.line = element_line(color = "orange")) } cars %>% ggplot() + * aes(x = speed) ``` ] .right-panel-bundle-auto[ <img src="themes_files/figure-html/bundle_auto_4_output-1.png" width="100%" /> ] --- class: split-40 count: false .left-panel-bundle-auto[ ```r my_theme <- function(){ theme(rect = element_rect(fill = "snow3")) + theme(text = element_text(family = "Times New Roman")) + theme(axis.title = element_text(color = "slateblue4")) + theme(title = element_text(color = "seagreen")) + theme(axis.line = element_line(color = "orange")) } cars %>% ggplot() + aes(x = speed) + * aes(y = dist) ``` ] .right-panel-bundle-auto[ <img src="themes_files/figure-html/bundle_auto_5_output-1.png" width="100%" /> ] --- class: split-40 count: false .left-panel-bundle-auto[ ```r my_theme <- function(){ theme(rect = element_rect(fill = "snow3")) + theme(text = element_text(family = "Times New Roman")) + theme(axis.title = element_text(color = "slateblue4")) + theme(title = element_text(color = "seagreen")) + theme(axis.line = element_line(color = "orange")) } cars %>% ggplot() + aes(x = speed) + aes(y = dist) + * geom_point() ``` ] .right-panel-bundle-auto[ <img src="themes_files/figure-html/bundle_auto_6_output-1.png" width="100%" /> ] --- class: split-40 count: false .left-panel-bundle-auto[ ```r my_theme <- function(){ theme(rect = element_rect(fill = "snow3")) + theme(text = element_text(family = "Times New Roman")) + theme(axis.title = element_text(color = "slateblue4")) + theme(title = element_text(color = "seagreen")) + theme(axis.line = element_line(color = "orange")) } cars %>% ggplot() + aes(x = speed) + aes(y = dist) + geom_point() + * my_theme() ``` ] .right-panel-bundle-auto[ <img src="themes_files/figure-html/bundle_auto_7_output-1.png" width="100%" /> ] <style> .left-panel-bundle-auto { color: #777; width: 49%; height: 92%; float: left; font-size: 80% } .right-panel-bundle-auto { width: 50%; float: right; padding-left: 1%; font-size: 80% } .middle-panel-bundle-auto { width: NA%; float: left; padding-left: 1%; font-size: 80% } </style> --- # More - [external themes](external_themes.html) - [theme modification with {ggeasy}](themes_ggeasy.Rmd) --- Next up is [the written language](ggsave.html) or saving plots as files. <style type="text/css"> .remark-code{line-height: 1.5; font-size: 60%} .column-left { float: left; width: 33.333%; } .column-right { float: right; width: 33.333%; } .column-center { display: inline-block; width: 33.333%; } </style> <!-- --- --> <!-- Some ideas from ["The Glamour of Graphics"](https://resources.rstudio.com/rstudio-conf-2020/the-glamour-of-graphics-william-chase) --> <!-- -- --> <!-- - engage a wider audience --> <!-- -- --> <!-- - aesthetic-usability effect --> <!-- -- --> <!-- - respect for your audience --> <!-- -- --> <!-- ## Glamour and Grammar etymological connection! --> <!-- --- --> <!-- # Layout --> <!-- -- --> <!-- - Mostly left alignment of text --> <!-- -- --> <!-- - titles - *plot* left alignment --> <!-- -- --> <!-- - no head tilting --> <!-- -- --> <!-- - get rid of labels if possible --> <!-- -- --> <!-- - rethink legend position, or alternatives: labeling data, or color mapping --> <!-- -- --> <!-- - be borders skeptical --> <!-- -- --> <!-- - be gridline skeptical --> <!-- -- --> <!-- - try to avoid legends --> <!-- -- --> <!-- - white space - use it! --> <!-- --- --> <!-- # Typography --> <!-- -- --> <!-- - effects tone --> <!-- -- --> <!-- - https://practicaltypography.com/ --> <!-- -- --> <!-- - https://fonts.google.com/ (source family) --> <!-- -- --> <!-- - typographic hiararchy - size, weight, spacing --> <!-- -- --> <!-- - don't use "oldstyle" numbers, do use *tabular* numbers --> <!-- -- --> <!-- - https://cran.r-project.org/web/packages/svglite/vignettes/fonts.html --> <!-- To be continued... [](https://cran.r-project.org/web/packages/svglite/vignettes/fonts.html) --> <!-- --- --> <!-- # Color --> <!-- Check out the [color](color.html) slides. --> <!-- -- --> <!-- - also eyedropper tool --> <!-- -- --> <!-- - use hue saturation value selection --> <!-- -- --> <!-- - non-white backgrounds -->