|
| 1 | +--- |
| 2 | +title: "knitr dark mode - thematic" |
| 3 | +format: |
| 4 | + html: |
| 5 | + theme: |
| 6 | + light: united |
| 7 | + dark: slate |
| 8 | + keep-md: true |
| 9 | +execute: |
| 10 | + echo: false |
| 11 | + warning: false |
| 12 | +_quarto: |
| 13 | + tests: |
| 14 | + html: |
| 15 | + ensureHtmlElements: |
| 16 | + - |
| 17 | + - 'body.quarto-light' |
| 18 | + - 'div.cell div.light-content' |
| 19 | + - 'div.cell div.dark-content' |
| 20 | + - 'div.cell div.cell-code pre.code-with-copy' |
| 21 | + - [] |
| 22 | +--- |
| 23 | + |
| 24 | +```{r} |
| 25 | +#| echo: false |
| 26 | +#| warning: false |
| 27 | +library(ggplot2) |
| 28 | +
|
| 29 | +ggplot_theme <- function(bgcolor, fgcolor) { |
| 30 | + theme_minimal(base_size = 11) %+% |
| 31 | + theme( |
| 32 | + panel.border = element_blank(), |
| 33 | + panel.grid.major.y = element_blank(), |
| 34 | + panel.grid.minor.y = element_blank(), |
| 35 | + panel.grid.major.x = element_blank(), |
| 36 | + panel.grid.minor.x = element_blank(), |
| 37 | + text = element_text(colour = fgcolor), |
| 38 | + axis.text = element_text(colour = fgcolor), |
| 39 | + rect = element_rect(colour = bgcolor, fill = bgcolor), |
| 40 | + plot.background = element_rect(fill = bgcolor, colour = NA), |
| 41 | + axis.line = element_line(colour = fgcolor), |
| 42 | + axis.ticks = element_line(colour = fgcolor) |
| 43 | + ) |
| 44 | +} |
| 45 | +
|
| 46 | +united_theme <- ggplot_theme("#ffffff", "#333333") |
| 47 | +slate_theme <- ggplot_theme("#282B30", "#aaaaaa") |
| 48 | +
|
| 49 | +colour_scale <- scale_colour_manual(values = c("darkorange", "purple", "cyan4")) |
| 50 | +``` |
| 51 | + |
| 52 | +### no crossref, no caption |
| 53 | + |
| 54 | +```{r} |
| 55 | +#| renderings: [light, dark] |
| 56 | +theme_set(united_theme) |
| 57 | +ggplot(mtcars, aes(mpg, wt)) + |
| 58 | + geom_point(aes(colour = factor(cyl))) + colour_scale |
| 59 | +theme_set(slate_theme) |
| 60 | +ggplot(mtcars, aes(mpg, wt)) + |
| 61 | + geom_point(aes(colour = factor(cyl))) + colour_scale |
| 62 | +``` |
| 63 | + |
| 64 | +### with crossref but no caption |
| 65 | + |
| 66 | +::: {#fig-thematic-ggplot} |
| 67 | +```{r} |
| 68 | +#| echo: true |
| 69 | +#| renderings: |
| 70 | +#| - dark |
| 71 | +#| - light |
| 72 | +theme_set(slate_theme) |
| 73 | +ggplot(mtcars, aes(mpg, disp)) + |
| 74 | + geom_point(aes(colour = factor(cyl))) + colour_scale |
| 75 | +theme_set(united_theme) |
| 76 | +ggplot(mtcars, aes(mpg, disp)) + |
| 77 | + geom_point(aes(colour = factor(cyl))) + colour_scale |
| 78 | +``` |
| 79 | +::: |
| 80 | + |
| 81 | +### with caption but no crossref |
| 82 | + |
| 83 | +<div> |
| 84 | + |
| 85 | +```{r} |
| 86 | +#| renderings: [dark] |
| 87 | +theme_set(slate_theme) |
| 88 | +ggplot(mtcars, aes(mpg, disp)) + |
| 89 | + geom_point(aes(colour = factor(cyl))) + colour_scale |
| 90 | +``` |
| 91 | + |
| 92 | +thematic - base r graphics |
| 93 | + |
| 94 | +</div> |
| 95 | + |
| 96 | +## patchwork |
| 97 | + |
| 98 | +### with crossref and caption |
| 99 | + |
| 100 | +::: {#fig-thematic-patchwork} |
| 101 | +```{r} |
| 102 | +#| renderings: [light, dark] |
| 103 | +theme_set(united_theme) |
| 104 | +ggplot(mtcars, aes(mpg, hp)) + |
| 105 | + geom_point(aes(colour = factor(cyl))) + colour_scale |
| 106 | +theme_set(slate_theme) |
| 107 | +ggplot(mtcars, aes(mpg, hp)) + |
| 108 | + geom_point(aes(colour = factor(cyl))) + colour_scale |
| 109 | +``` |
| 110 | + |
| 111 | +mtcars - mpg vs hp |
| 112 | +::: |
| 113 | + |
| 114 | +Here's a [link](https://example.com). |
| 115 | + |
| 116 | +{{< lipsum 3 >}} |
0 commit comments