-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathskeleton.Rmd
83 lines (61 loc) · 1.77 KB
/
skeleton.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
79
80
81
82
---
title: "Your title"
author: "Your name"
output:
xaringan::moon_reader:
css: [useR, useR-fonts]
lib_dir: libs
---
class: chapter-slide
# Chapter
---
## Header 2
Some text
### Header 3
```{r}
# some code
seq(1:5)
```
---
## Creating some plots
We will use the [viridis](https://cran.r-project.org/web/packages/viridis/vignettes/intro-to-viridis.html) package to create some colorblind-friendly plots.
Let's see how the graph looks like with various color-vision-deficiency [simulations](https://github.com/clauswilke/colorblindr):
```{r, echo=FALSE, message=FALSE}
library(ggplot2)
library(colorblindr)
library(viridis)
theme_useR <- function(base_size = 28) {
theme_bw(base_size = base_size) +
theme(legend.margin = margin(), legend.title = element_blank())
}
```
```{r}
fig <- ggplot(iris, aes(Sepal.Length, fill = Species)) +
geom_density(alpha = 0.7) + theme_useR() +
theme(legend.position = c(0.8, 0.9),legend.margin = margin(),
legend.title = element_blank())
fig_grid <- cvd_grid(fig)
```
.center[
```{r,echo=FALSE, fig.show="hold", out.width="40%"}
fig
cvd_grid(ggplot(iris, aes(Sepal.Length, fill = Species)) +
geom_density(alpha = 0.7) + theme_useR(base_size = 18) +
theme(legend.position = c(0.7, 0.8)) )
```
]
---
Let's use a color scale that works better
```{r}
fig2 <- ggplot(iris, aes(Sepal.Length, fill = Species)) +
geom_density(alpha = 0.8) + theme_useR() +
theme(legend.position = c(0.8, 0.9))+
scale_fill_viridis(discrete = TRUE)
fig_grid2 <- cvd_grid(fig2)
```
```{r,echo=FALSE, fig.show="hold", out.width="48%"}
fig2
cvd_grid(ggplot(iris, aes(Sepal.Length, fill = Species)) +
geom_density(alpha = 0.8) + theme_useR(base_size = 18) +
theme(legend.position = c(0.7, 0.8))+ scale_fill_viridis(discrete = TRUE) )
```