We use the following packages in this Practical:
library(dplyr) # for data manipulation
library(magrittr) # for pipes
library(ggplot2) # for visualization
library(mice) # for the boys data
mean = 5
and sd = 1
- \(N(5, 1)\),anscombe
data setx4
, y4
) on the anscombe
data setThe boys
dataset is part of package mice
. It is a subset of 748 Dutch boystaken from the Fourth Dutch Growth Study. It’s columns record a variety of growth measures. Inspect the help for boys
dataset and make yourself familiar with its contents.**
To learn more about the contents of the data, use one of the two following help commands:
help(boys)
?boys
boys
data are sorted based on age
. Verify this.hgt
and wgt
in the boys
data set from package mice
.boys
data set, hgt
is recorded in centimeters. Use a pipe to transform hgt
in the boys
dataset to height in meters and verify the transformationhgt
, wgt
) two times: once for hgt
in meters and once for hgt
in centimeters. Make the points in the ‘centimeter’ plot red
and in the ‘meter’ plot blue
. plot()
is the core plotting function in R
. Find out more about plot()
: Try both the help in the help-pane and ?plot
in the console. Look at the examples by running example(plot)
.age
and bmi
in the mice::boys
data setbmi < 18.5
use color = "light blue"
bmi > 18.5 & bmi < 25
use color = "light green"
bmi > 25 & bmi < 30
use color = "orange"
bmi > 30
use color = "red"
Hint: it may help to expand the data set with a new variable.
age
in the boys
data setreg
in the boys data sethgt
with different boxes for reg
in the boys
data setage
with different curves for boys from the city
and boys from rural areas (!city
).hgt
in the boys
data set, that displays for every age
year that year’s mean height in deviations from the overall average hgt
In other words; recreate the following plot:
End of Practical
ggplot2
reference pagemagrittr
R
for Data Science - Chapter 18 on pipes