-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
0e3afab
commit 6bd7fa8
Showing
76 changed files
with
41,416 additions
and
3 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
{ | ||
"hash": "a6f2a331e578b8b930837b5dfebc2159", | ||
"result": { | ||
"engine": "knitr", | ||
"markdown": "---\ntitle: \"Figure design\"\nauthor: \"Claus O. Wilke\"\ndate: last-modified\nformat: \n revealjs:\n theme:\n - default\n - Wilke-theme.scss\n auto-stretch: false\n chalkboard: true\nexecute:\n fig-format: svg\n fig-asp: 0.618\n fig-width: 5.5\n---\n\n\n\n\n\n# Working with ggplot themes\n\n---\n\n## Using ready-made themes\n\n::: {.small-font}\n\n\n::: {.cell}\n\n```{.r .cell-code}\nggplot(penguins, aes(flipper_length_mm, body_mass_g, color = species)) +\n geom_point()\n # default theme is theme_gray()\n```\n\n::: {.cell-output-display}\n![ ](figure-design_files/figure-revealjs/penguins-complete-themes-1.svg){width=60%}\n:::\n:::\n\n\n:::\n\n\n## Customizing theme elements\n\n::: {.tiny-font}\n\n\n::: {.cell output-location='column'}\n\n```{.r .cell-code}\nggplot(penguins) +\n aes(flipper_length_mm, body_mass_g) +\n geom_point(aes(color = species)) +\n theme_minimal_grid()\n```\n\n::: {.cell-output-display}\n![ ](figure-design_files/figure-revealjs/penguins-theme-elements1-1.svg){width=100%}\n:::\n:::\n\n\n:::\n\n## Customizing theme elements\n\n::: {.tiny-font}\n\n\n::: {.cell output-location='column'}\n\n```{.r .cell-code}\nggplot(penguins) +\n aes(flipper_length_mm, body_mass_g) +\n geom_point(aes(color = species)) +\n theme_minimal_grid() +\n theme(\n # change overall font family\n # (requires font to be available)\n text = element_text(\n family = \"Comic Sans MS\"\n )\n )\n```\n\n::: {.cell-output-display}\n![ ](figure-design_files/figure-revealjs/penguins-theme-elements2-1.svg){width=100%}\n:::\n:::\n\n\n:::\n\n## Customizing theme elements\n\n::: {.tiny-font}\n\n\n::: {.cell output-location='column'}\n\n```{.r .cell-code}\nggplot(penguins) +\n aes(flipper_length_mm, body_mass_g) +\n geom_point(aes(color = species)) +\n theme_minimal_grid() +\n theme(\n # change color of axis titles\n axis.title = element_text(\n color = \"royalblue2\"\n )\n )\n```\n\n::: {.cell-output-display}\n![ ](figure-design_files/figure-revealjs/penguins-theme-elements3-1.svg){width=100%}\n:::\n:::\n\n\n:::\n\n## Customizing theme elements\n\n::: {.tiny-font}\n\n\n::: {.cell output-location='column'}\n\n```{.r .cell-code}\nggplot(penguins) +\n aes(flipper_length_mm, body_mass_g) +\n geom_point(aes(color = species)) +\n theme_minimal_grid() +\n theme(\n # change color of only the x axis title\n axis.title.x = element_text(\n color = \"royalblue2\"\n )\n )\n```\n\n::: {.cell-output-display}\n![ ](figure-design_files/figure-revealjs/penguins-theme-elements4-1.svg){width=100%}\n:::\n:::\n\n\n:::\n\n## Customizing theme elements\n\n::: {.tiny-font}\n\n\n::: {.cell output-location='column'}\n\n```{.r .cell-code}\nggplot(penguins) +\n aes(flipper_length_mm, body_mass_g) +\n geom_point(aes(color = species)) +\n theme_minimal_grid() +\n theme(\n # change all text colors?\n # why does it not work?\n text = element_text(color = \"royalblue2\")\n )\n```\n\n::: {.cell-output-display}\n![ ](figure-design_files/figure-revealjs/penguins-theme-elements5-1.svg){width=100%}\n:::\n:::\n\n\n:::\n\n## Customizing theme elements\n\n::: {.tiny-font}\n\n\n::: {.cell output-location='column'}\n\n```{.r .cell-code}\nggplot(penguins) +\n aes(flipper_length_mm, body_mass_g) +\n geom_point(aes(color = species)) +\n theme_minimal_grid() +\n theme(\n text = element_text(color = \"royalblue2\"),\n axis.text = element_text(\n color = \"royalblue2\"\n )\n )\n```\n\n::: {.cell-output-display}\n![ ](figure-design_files/figure-revealjs/penguins-theme-elements6-1.svg){width=100%}\n:::\n:::\n\n\n:::\n\n::: {.fragment .small-font}\nThe element `axis.text` has its own color set in the theme. Therefore it doesn't inherit from `text`.\n:::\n\n\n## Horizontal and vertical alignment\n\n::: {.tiny-font}\n\n\n::: {.cell output-location='column'}\n\n```{.r .cell-code}\nggplot(penguins) +\n aes(flipper_length_mm, body_mass_g) +\n geom_point(aes(color = species)) +\n theme_minimal_grid() +\n theme(\n axis.title.x = element_text(\n # horizontal justification\n # (0 = left)\n hjust = 0\n )\n )\n```\n\n::: {.cell-output-display}\n![ ](figure-design_files/figure-revealjs/penguins-theme-elements7-1.svg){width=100%}\n:::\n:::\n\n\n:::\n\n## Horizontal and vertical alignment\n\n::: {.tiny-font}\n\n\n::: {.cell output-location='column'}\n\n```{.r .cell-code}\nggplot(penguins) +\n aes(flipper_length_mm, body_mass_g) +\n geom_point(aes(color = species)) +\n theme_minimal_grid() +\n theme(\n axis.title.x = element_text(\n # horizontal justification\n # (0.5 = center)\n hjust = 0.5\n )\n )\n```\n\n::: {.cell-output-display}\n![ ](figure-design_files/figure-revealjs/penguins-theme-elements8-1.svg){width=100%}\n:::\n:::\n\n\n:::\n\n## Horizontal and vertical alignment\n\n::: {.tiny-font}\n\n\n::: {.cell output-location='column'}\n\n```{.r .cell-code}\nggplot(penguins) +\n aes(flipper_length_mm, body_mass_g) +\n geom_point(aes(color = species)) +\n theme_minimal_grid() +\n theme(\n axis.title.x = element_text(\n # horizontal justification\n # (1 = right)\n hjust = 1\n )\n )\n```\n\n::: {.cell-output-display}\n![ ](figure-design_files/figure-revealjs/penguins-theme-elements9-1.svg){width=100%}\n:::\n:::\n\n\n:::\n\n## Horizontal and vertical alignment\n\n::: {.tiny-font}\n\n\n::: {.cell output-location='column'}\n\n```{.r .cell-code}\nggplot(penguins) +\n aes(flipper_length_mm, body_mass_g) +\n geom_point(aes(color = species)) +\n theme_minimal_grid() +\n theme(\n axis.text.y = element_text(\n # vertical justification\n # (0 = bottom)\n vjust = 0\n )\n )\n```\n\n::: {.cell-output-display}\n![ ](figure-design_files/figure-revealjs/penguins-theme-elements10-1.svg){width=100%}\n:::\n:::\n\n\n:::\n\n## Horizontal and vertical alignment\n\n::: {.tiny-font}\n\n\n::: {.cell output-location='column'}\n\n```{.r .cell-code}\nggplot(penguins) +\n aes(flipper_length_mm, body_mass_g) +\n geom_point(aes(color = species)) +\n theme_minimal_grid() +\n theme(\n axis.text.y = element_text(\n # vertical justification\n # (0.5 = center)\n vjust = 0.5\n )\n )\n```\n\n::: {.cell-output-display}\n![ ](figure-design_files/figure-revealjs/penguins-theme-elements11-1.svg){width=100%}\n:::\n:::\n\n\n:::\n\n## Horizontal and vertical alignment\n\n::: {.tiny-font}\n\n\n::: {.cell output-location='column'}\n\n```{.r .cell-code}\nggplot(penguins) +\n aes(flipper_length_mm, body_mass_g) +\n geom_point(aes(color = species)) +\n theme_minimal_grid() +\n theme(\n axis.text.y = element_text(\n # vertical justification\n # (1 = top)\n vjust = 1\n )\n )\n```\n\n::: {.cell-output-display}\n![ ](figure-design_files/figure-revealjs/penguins-theme-elements12-1.svg){width=100%}\n:::\n:::\n\n\n:::\n\n## Remove elements entirely: `element_blank()`\n\n::: {.tiny-font}\n\n\n::: {.cell output-location='column'}\n\n```{.r .cell-code}\nggplot(penguins) +\n aes(flipper_length_mm, body_mass_g) +\n geom_point(aes(color = species)) +\n theme_minimal_grid() +\n theme(\n # all text gone\n text = element_blank()\n )\n```\n\n::: {.cell-output-display}\n![ ](figure-design_files/figure-revealjs/penguins-theme-elements13-1.svg){width=100%}\n:::\n:::\n\n\n:::\n\n\n## Remove elements entirely: `element_blank()`\n\n::: {.tiny-font}\n\n\n::: {.cell output-location='column'}\n\n```{.r .cell-code}\nggplot(penguins) +\n aes(flipper_length_mm, body_mass_g) +\n geom_point(aes(color = species)) +\n theme_minimal_grid() +\n theme(\n # no axis titles\n axis.title = element_blank()\n )\n```\n\n::: {.cell-output-display}\n![ ](figure-design_files/figure-revealjs/penguins-theme-elements14-1.svg){width=100%}\n:::\n:::\n\n\n:::\n\n## Set background color: `element_rect()`\n\n::: {.tiny-font}\n\n\n::: {.cell output-location='column'}\n\n```{.r .cell-code}\nggplot(penguins) +\n aes(flipper_length_mm, body_mass_g) +\n geom_point(aes(color = species)) +\n theme_minimal_grid() +\n theme(\n plot.background = element_rect(\n fill = \"aliceblue\"\n )\n )\n```\n\n::: {.cell-output-display}\n![ ](figure-design_files/figure-revealjs/penguins-theme-elements15-1.svg){width=100%}\n:::\n:::\n\n\n:::\n\n## Set background color: `element_rect()`\n\n::: {.tiny-font}\n\n\n::: {.cell output-location='column'}\n\n```{.r .cell-code}\nggplot(penguins) +\n aes(flipper_length_mm, body_mass_g) +\n geom_point(aes(color = species)) +\n theme_minimal_grid() +\n theme(\n panel.background = element_rect(\n fill = \"aliceblue\"\n )\n )\n```\n\n::: {.cell-output-display}\n![ ](figure-design_files/figure-revealjs/penguins-theme-elements16-1.svg){width=100%}\n:::\n:::\n\n\n:::\n\n## Set background color: `element_rect()`\n\n::: {.tiny-font}\n\n\n::: {.cell output-location='column'}\n\n```{.r .cell-code}\nggplot(penguins) +\n aes(flipper_length_mm, body_mass_g) +\n geom_point(aes(color = species)) +\n theme_minimal_grid() +\n theme(\n legend.box.background = element_rect(\n fill = \"aliceblue\",\n color = \"steelblue4\" # line color\n )\n )\n```\n\n::: {.cell-output-display}\n![ ](figure-design_files/figure-revealjs/penguins-theme-elements17-1.svg){width=100%}\n:::\n:::\n\n\n:::\n\n## Set background color: `element_rect()`\n\n::: {.tiny-font}\n\n\n::: {.cell output-location='column'}\n\n```{.r .cell-code}\nggplot(penguins) +\n aes(flipper_length_mm, body_mass_g) +\n geom_point(aes(color = species)) +\n theme_minimal_grid() +\n theme(\n legend.box.background = element_rect(\n fill = \"aliceblue\",\n color = \"steelblue4\" # line color\n ),\n legend.box.margin = margin(7, 7, 7, 7)\n )\n```\n\n::: {.cell-output-display}\n![ ](figure-design_files/figure-revealjs/penguins-theme-elements18-1.svg){width=100%}\n:::\n:::\n\n\n:::\n\n## Move the legend: `legend.position`\n\n::: {.tiny-font}\n\n\n::: {.cell output-location='column'}\n\n```{.r .cell-code}\nggplot(penguins) +\n aes(flipper_length_mm, body_mass_g) +\n geom_point(aes(color = species)) +\n theme_minimal_grid() +\n theme(\n legend.box.background = element_rect(\n fill = \"aliceblue\",\n color = \"steelblue4\" # line color\n ),\n legend.box.margin = margin(7, 7, 7, 7),\n # legend on top of plot\n legend.position = \"top\"\n )\n```\n\n::: {.cell-output-display}\n![ ](figure-design_files/figure-revealjs/penguins-theme-elements19-1.svg){width=100%}\n:::\n:::\n\n\n:::\n\n\n## Move the legend: `legend.position`\n\n::: {.tiny-font}\n\n\n::: {.cell output-location='column'}\n\n```{.r .cell-code}\nggplot(penguins) +\n aes(flipper_length_mm, body_mass_g) +\n geom_point(aes(color = species)) +\n theme_minimal_grid() +\n theme(\n legend.box.background = element_rect(\n fill = \"aliceblue\",\n color = \"steelblue4\" # line color\n ),\n legend.box.margin = margin(7, 7, 7, 7),\n # legend inside plot\n legend.position = \"inside\", \n # relative position inside plot panel\n legend.position.inside = c(0.98, 0.02),\n # justification relative to position\n legend.justification = c(1, 0)\n )\n```\n\n::: {.cell-output-display}\n![ ](figure-design_files/figure-revealjs/penguins-theme-elements20-1.svg){width=100%}\n:::\n:::\n\n\n:::\n\n<!-- Segment ends here -->\n\n## Further reading\n\n::: {.small-font}\n- Fundamentals of Data Visualization: [Chapter 23: Balance the data and the context](https://clauswilke.com/dataviz/balance-data-context.html)\n- Data Visualization—A Practical Introduction: [Chapter 8.3: Change the appearance of plots with themes](https://socviz.co/refineplots.html#change-the-appearance-of-plots-with-themes)\n- ggplot2 reference documentation: [Complete themes](https://ggplot2.tidyverse.org/reference/ggtheme.html)\n- ggplot2 reference documentation: [Modify components of a theme](https://ggplot2.tidyverse.org/reference/theme.html)\n:::", | ||
"supporting": [ | ||
"figure-design_files" | ||
], | ||
"filters": [ | ||
"rmarkdown/pagebreak.lua" | ||
], | ||
"includes": { | ||
"include-after-body": [ | ||
"\n<script>\n // htmlwidgets need to know to resize themselves when slides are shown/hidden.\n // Fire the \"slideenter\" event (handled by htmlwidgets.js) when the current\n // slide changes (different for each slide format).\n (function () {\n // dispatch for htmlwidgets\n function fireSlideEnter() {\n const event = window.document.createEvent(\"Event\");\n event.initEvent(\"slideenter\", true, true);\n window.document.dispatchEvent(event);\n }\n\n function fireSlideChanged(previousSlide, currentSlide) {\n fireSlideEnter();\n\n // dispatch for shiny\n if (window.jQuery) {\n if (previousSlide) {\n window.jQuery(previousSlide).trigger(\"hidden\");\n }\n if (currentSlide) {\n window.jQuery(currentSlide).trigger(\"shown\");\n }\n }\n }\n\n // hookup for slidy\n if (window.w3c_slidy) {\n window.w3c_slidy.add_observer(function (slide_num) {\n // slide_num starts at position 1\n fireSlideChanged(null, w3c_slidy.slides[slide_num - 1]);\n });\n }\n\n })();\n</script>\n\n" | ||
] | ||
}, | ||
"engineDependencies": {}, | ||
"preserve": {}, | ||
"postProcess": true | ||
} | ||
} |
Oops, something went wrong.