-
Notifications
You must be signed in to change notification settings - Fork 432
Expand file tree
/
Copy pathggplot-duobrand-doc-renderings.qmd
More file actions
130 lines (104 loc) · 2.6 KB
/
ggplot-duobrand-doc-renderings.qmd
File metadata and controls
130 lines (104 loc) · 2.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
---
title: "knitr dark mode - ggplot"
brand:
light: united-brand.yml
dark: slate-brand.yml
execute:
echo: false
warning: false
renderings: [light, dark]
_quarto:
tests:
html:
ensureHtmlElements:
-
- 'body.quarto-light'
- 'div.cell div.light-content'
- 'div.cell div.dark-content'
- 'div.cell div.cell-code pre.code-with-copy'
- []
---
```{r}
#| echo: false
#| warning: false
library(ggplot2)
ggplot_theme <- function(bgcolor, fgcolor) {
theme_minimal(base_size = 11) %+%
theme(
panel.border = element_blank(),
panel.grid.major.y = element_blank(),
panel.grid.minor.y = element_blank(),
panel.grid.major.x = element_blank(),
panel.grid.minor.x = element_blank(),
text = element_text(colour = fgcolor),
axis.text = element_text(colour = fgcolor),
rect = element_rect(colour = bgcolor, fill = bgcolor),
plot.background = element_rect(fill = bgcolor, colour = NA),
axis.line = element_line(colour = fgcolor),
axis.ticks = element_line(colour = fgcolor)
)
}
brand_ggplot <- function(brand_yml) {
brand <- yaml::yaml.load_file(brand_yml)
ggplot_theme(brand$color$background, brand$color$foreground)
}
united_theme <- brand_ggplot("united-brand.yml")
slate_theme <- brand_ggplot("slate-brand.yml")
colour_scale <- scale_colour_manual(values = c("darkorange", "purple", "cyan4"))
```
### no crossref, no caption
```{r}
ggplot(mtcars, aes(mpg, wt)) +
geom_point(aes(colour = factor(cyl))) +
united_theme +
colour_scale
ggplot(mtcars, aes(mpg, wt)) +
geom_point(aes(colour = factor(cyl))) +
slate_theme +
colour_scale
```
### with crossref but no caption
and `echo: true`
::: {#fig-ggplot}
```{r}
#| echo: true
#| renderings: [dark, light]
# override renderings order
ggplot(mtcars, aes(mpg, disp)) +
geom_point(aes(colour = factor(cyl))) +
slate_theme +
colour_scale
ggplot(mtcars, aes(mpg, disp)) +
geom_point(aes(colour = factor(cyl))) +
united_theme +
colour_scale
```
:::
### with caption but no crossref
<div>
```{r}
#| renderings: [dark]
# override number of renderings
ggplot(mtcars, aes(mpg, disp)) +
geom_point(aes(colour = factor(cyl))) +
slate_theme +
colour_scale
```
ggplot - dark only
</div>
### with crossref and caption
::: {#fig-ggplot-mpg-hp}
```{r}
ggplot(mtcars, aes(mpg, hp)) +
geom_point(aes(colour = factor(cyl))) +
united_theme +
colour_scale
ggplot(mtcars, aes(mpg, hp)) +
geom_point(aes(colour = factor(cyl))) +
slate_theme +
colour_scale
```
mtcars - mpg vs hp
:::
Here's a [link](https://example.com).
{{< lipsum 3 >}}