-
Notifications
You must be signed in to change notification settings - Fork 0
/
phd day workshop.Rmd
163 lines (94 loc) · 3.01 KB
/
phd day workshop.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
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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
---
title: "Beyond barcharts"
output: html_notebook
---
# Bar chart alternatives
Let's meet the iris dataset!
Read more about it in the R help page for iris
```{r}
head(iris)
```
## ggplot basics
Let's do ggplot basics now!
Make a jitterplot with `geom_jitter()` Set the `x aesthetic` to `Species` and the `y aesthetic` to `Sepal.Length`
```{r}
```
## Barchart in ggplot
Let's make the same plot, but as a barchart.
Do you already know `stat_summary()`?
It's ggplot's best kept secret.
Replace `geom_jitter()` with `stat_summary(geom = 'bar')` and make a barchart.
Second, add `stat_summary(geom = 'errorbar')`
```{r}
```
That's your barchart right there!
Is it a beauty, no not quite, but we can fine-tune that in a later stage.
## Density alternatives
Let's make a couple alternatives.
### try `geom_violin()`
```{r}
```
### try `geom_density`
Replace the `x` aesthetic for `col = Species` , and maybe swap x and y axes.
You can add the `linetype` aesthetic as well!
that way it works in greyscale print.
```{r}
```
-------====== Wait here please, we'll plenary get up to speed in a second ===========------
## point/count alternatives
### dotplot
Similar to a violin plot, but shows the actual data points.
Use `geom_dotplot(binaxis = 'y',stackdir = 'center')`
```{r}
```
### histogram
```{r}
```
### boxplot
```{r}
```
-------====== Wait here please, we'll plenary get up to speed in a second ===========------
# Combining shapes!
ggplot can layer shapes on top of one another.
We can use this to our advantage, and add more data in our figure.
### Boxplot with jitter
Make a boxplot like before, but add the datapoints with `geom_jitter`.
Make the datapoints transparent and grey if you know how.
```{r}
```
### dotplot with median
Was that too easy, then here is a hard one!
Next, make a dotplot, but add a red line that displays the median.
Use stat summary and the cheatsheet.
*hint: `stat_summary()` has a `fun=` argument for determining what function you want used to summarise the data.*
```{r}
```
# Extension packages
## GGdist
ggdist, deals with displaying distributions, perfect!
Have a look at their cheatsheet.
[ggdist cheatsheet](https://github.com/mjskay/ggdist/blob/master/figures-source/cheat_sheet-slabinterval.pdf){.uri}
Try a ggdist visualisation on the iris dataset.
```{r}
```
# A figure of your own?
Do you have a (barchart?) figure of your own at hand?
Maybe play with that!
I'll be around to help out.
```{r}
```
## Alternative:
Formatting your data into the right shape is as hard as working ggplot itself.
I'd like you to try to make a boxplot of the irisdataset.
On the x axis, should be the different lengths that were measured.
The fill colour should be the Species, and on the y axis the actual measured length.
Can you manage?
Now make your favourite alternative, maybe a dotplot with a crossbar?
Or some other shape you may have found in the ggdist package.
```{r}
```
## Challenge!
Feeling up to a challenge, try to re-create this:
![](images/clipboard-819503216.png)
```{r}
```