-
Notifications
You must be signed in to change notification settings - Fork 15
/
17-themes.Rmd
78 lines (52 loc) · 1.71 KB
/
17-themes.Rmd
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
# Themes
**Learning objectives:**
- How can I customize the output of my plot
- What are the functions `theme_<function>()` and `theme()`
## Theme
Plots can be customized by adding these function to your plot:
- scale_fill/color_<function>
- theme_<function>
- theme()
- ...
### Complete themes
In ggplo2 there are preset themes ready to use:
```{r message=FALSE, warning=FALSE, paged.print=FALSE}
library(tidyverse)
df <- data.frame(x = 1:3, y = 1:3)
base <- ggplot(df, aes(x, y)) + geom_point()
p1<-base + theme_grey() + ggtitle("theme_grey()")
p2<-base + theme_bw() + ggtitle("theme_bw()")
p3<-base + theme_linedraw() + ggtitle("theme_linedraw()")
library(patchwork)
p1+p2+p3
```
```{r}
p4<-base + theme_light() + ggtitle("theme_light()")
p5<- base + theme_dark() + ggtitle("theme_dark()")
p6<-base + theme_minimal() + ggtitle("theme_minimal()")
p4+p5+p6
```
```{r}
p7<-base + theme_classic() + ggtitle("theme_classic()")
p8<-base + theme_void() + ggtitle("theme_void()")
p7+p8
```
Or, you can use other packages such as {ggthemes} or other here: [ggplot extension gallery](https://exts.ggplot2.tidyverse.org/gallery/)
```{r}
library(ggthemes)
p9<-base + theme_tufte() + ggtitle("theme_tufte()")
p10<-base + theme_solarized() + ggtitle("theme_solarized()")
p11<-base + theme_excel() + ggtitle("theme_excel()")
p9+p10+p11
```
- Modifying complete theme components with `theme()` function
## Plot elements of a theme
- Axis elements
- Legend elements
- Panel elements
- Faceting elements
Look at `?theme()` funtion in your help pane of RStudio for more info.
## Meeting Videos
### Cohort 1
`r knitr::include_url("https://www.youtube.com/embed/gKVGjht4N20")`
`r knitr::include_url("https://www.youtube.com/embed/ihl-15wL7zY")`