-
Notifications
You must be signed in to change notification settings - Fork 14
/
io27-learn_consort.Rmd
executable file
·153 lines (115 loc) · 4.03 KB
/
io27-learn_consort.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
---
title: "Tutorial"
output: learnr::tutorial
always_allow_html: true
runtime: shiny_prerendered
---
```{r setup, include=FALSE}
library(learnr)
knitr::opts_chunk$set(echo = FALSE)
library(tidyverse)
```
## Setting up ggplot for CONSORT
### Exercise 1
*Here's a simple exercise with an empty code chunk provided for entering the answer.*
ggplot is based on the grammar of graphics, so that layers are added one at a time.
The layers are
1. Data
2. Aesthetics
3. Scales
4. Geometric objects
5. Statistics (calculated)
6. Facets, if any
7. Coordinate System
The first layer is the axis grid, sized based on the available data.
If you call ggplot with data and an aesthetic layer, but no geom,
you will get the basic grid and axes, but not plotted data.
Edit the R code below to make a tall grid that is 100 units wide by 200 units tall:
```{r setup_grid, exercise=TRUE}
# This example sets up a grid that is 45 wide by 90 tall (before editing)
data <- tibble(x=1:45, y = seq(from= 2, to=90,by =2))
ggplot(aes(x, y), data = data) +
theme_bw()
```
## Topic 2
### Adding rectangles
Use the example of the tall grid above to make a grid,
and place a geom_rect() near the top.
the arguments for geom-rect include:
Parameters
* xmin - (required) left edge of rectangle
* xmax - (required) right edge of rectangle
* ymin - (required) bottom edge of rectangle
* ymax - (required) top edge of rectangle
* size - (default: 0.5) line width of the rectangle's outline
* linetype - (default: 1=solid) line type of the rectangle's outline
* color - (default: NA=no outline) color of the rectangle's outline
* fill - (default: "grey20") fill color of the rectangle
* alpha - (default: 1=opaque) transparency of the rectangle's fill
Experiment with the arguments.
Then add a rectangle with a different appearance near the bottom.
```{r rectangles, exercise=TRUE}
# This example sets up a grid that is 45 wide by 90 tall (before editing)
data <- tibble(x=1:45, y = seq(from= 2, to=90,by =2))
ggplot(aes(x, y), data = data) +
theme_bw() +
geom_rect(xmin= ,
xmax= ,
ymin= ,
ymax= ,
size= ,
fill= )
```
## Topic 3
### Adding text
Use the tall grid with rectangles,
then add text in the boxes with annotate.
Annotate takes the form of a geom:
annotate("text", x = 4, y = 25, label = "Some text")
You can also use color, size, etc. as arguments,
and annotate with "rect", or "segment", or "pointrange"
https://ggplot2.tidyverse.org/reference/annotate.html
Try to add text inside your boxes.
you may want to use a small size=2 to start.
```{r text, exercise=TRUE}
# This example sets up a grid that is 45 wide by 90 tall (before editing)
data <- tibble(x=1:45, y = seq(from= 2, to=90,by =2))
ggplot(aes(x, y), data = data) +
theme_bw() +
geom_rect(xmin= ,
xmax= ,
ymin= ,
ymax= ,
size= ,
fill= ) +
annotate("text", x = 4, y = 25, label = "Some text")
```
## Topic 4
### Adding line segments / arrows
Use your grid and boxes with text, then
connect them with arrows to make a flow diagram
You will add arrows with geom_segment()
Use help or ?? to look up the arguments for geom_segment()
An example of one arrow segment is provided below to get you started. Add this arrow, then move it to
where you want it to make flow diagrams by changing
x, xend, y, and yend.
https://ggplot2.tidyverse.org/reference/geom_segment.html
```{r arrows, exercise=TRUE}
# This example sets up a grid that is 45 wide by 90 tall (before editing)
data <- tibble(x=1:45, y = seq(from= 2, to=90,by =2))
ggplot(aes(x, y), data = data) +
theme_bw() +
geom_rect(xmin= ,
xmax= ,
ymin= ,
ymax= ,
size= ,
fill= ) +
annotate("text", x = 4, y = 25, label = "Some text") +
geom_segment(
x=2, xend=2, y=49, yend=15.3,
size=0.15, linejoin = "mitre", lineend = "butt",
arrow = arrow(length = unit(1, "mm"), type= "closed"))
```
Okay, now you have a simple flow diagram.
You can use these skills to build your own CONSORT diagram!