Primary exercises
In the survey dataset:
- The variables
span1
andspan2
are of the same type representing the span of the writing hand and the non-writing hand respectively. We would like to analyse these values in groups. To do this we need to convert the variablesspan1
andspan2
into variablesspan
andsize
withspan
ranging over span1 and span2 andsize
over the values ofspan1
andspan2
variables.
survey %>% pivot_longer(c(span1,span2), names_to = "span", values_to = "size")
# A tibble: 466 × 13
name gender hand fold pulse clap exercise smokes height m.i age span size
<chr> <chr> <chr> <chr> <dbl> <chr> <chr> <chr> <dbl> <chr> <dbl> <chr> <dbl>
1 Alyson female right right 92 left some never 173 metric 18.2 span1 18.5
2 Alyson female right right 92 left some never 173 metric 18.2 span2 18
3 Todd male left right 104 left none regul 178. imperial 17.6 span1 19.5
4 Todd male left right 104 left none regul 178. imperial 17.6 span2 20.5
5 Gerald male right left 87 neither none occas NA <NA> 16.9 span1 18
6 Gerald male right left 87 neither none occas NA <NA> 16.9 span2 13.3
7 Robert male right right NA neither none never 160 metric 20.3 span1 18.8
8 Robert male right right NA neither none never 160 metric 20.3 span2 18.9
9 Dustin male right neither 35 right some never 165 metric 23.7 span1 20
10 Dustin male right neither 35 right some never 165 metric 23.7 span2 20
# … with 456 more rows
- Reproduce the following plot:
ggplot(survey %>% pivot_longer(c(span1,span2), names_to = "span", values_to = "size")) +
aes(x=gender, y=size, color=span) + geom_boxplot()