|
| 1 | +--- |
| 2 | +title: "dark brand - ggplot" |
| 3 | +brand: |
| 4 | + light: blue-background.yml |
| 5 | + dark: red-background.yml |
| 6 | +theme: |
| 7 | + light: simplex |
| 8 | + dark: cyborg # same effect as [brand, cyborg] |
| 9 | +execute: |
| 10 | + echo: false |
| 11 | + warning: false |
| 12 | +--- |
| 13 | + |
| 14 | +```{r} |
| 15 | +#| echo: false |
| 16 | +#| warning: false |
| 17 | +library(ggplot2) |
| 18 | +
|
| 19 | +ggplot_theme <- function(bgcolor, fgcolor) { |
| 20 | + theme_minimal(base_size = 11) %+% |
| 21 | + theme( |
| 22 | + panel.border = element_blank(), |
| 23 | + panel.grid.major.y = element_blank(), |
| 24 | + panel.grid.minor.y = element_blank(), |
| 25 | + panel.grid.major.x = element_blank(), |
| 26 | + panel.grid.minor.x = element_blank(), |
| 27 | + text = element_text(colour = fgcolor), |
| 28 | + axis.text = element_text(colour = fgcolor), |
| 29 | + rect = element_rect(colour = bgcolor, fill = bgcolor), |
| 30 | + plot.background = element_rect(fill = bgcolor, colour = NA), |
| 31 | + axis.line = element_line(colour = fgcolor), |
| 32 | + axis.ticks = element_line(colour = fgcolor) |
| 33 | + ) |
| 34 | +} |
| 35 | +
|
| 36 | +brand_ggplot <- function(brand_yml) { |
| 37 | + brand <- yaml::yaml.load_file(brand_yml) |
| 38 | + ggplot_theme(brand$color$background, brand$color$foreground) |
| 39 | +} |
| 40 | +
|
| 41 | +blue_theme <- brand_ggplot("blue-background.yml") |
| 42 | +red_theme <- brand_ggplot("red-background.yml") |
| 43 | +
|
| 44 | +colour_scale <- scale_colour_manual(values = c("darkorange", "purple", "cyan4")) |
| 45 | +``` |
| 46 | + |
| 47 | + |
| 48 | +```{r} |
| 49 | +#| renderings: [light, dark] |
| 50 | +ggplot(mtcars, aes(mpg, wt)) + |
| 51 | + geom_point(aes(colour = factor(cyl))) + blue_theme + colour_scale |
| 52 | +ggplot(mtcars, aes(mpg, wt)) + |
| 53 | + geom_point(aes(colour = factor(cyl))) + red_theme + colour_scale |
| 54 | +``` |
0 commit comments