Exercise 1.1
Let’s load the iris dataset again.
Remember that there often many ways to solve the same problem. The three lines of code below produce the same result in three different ways.
sum(iris$Sepal.Length > 5)
[1] 118
iris %>% summarize(sum(Sepal.Length > 5)) %>% pull()
[1] 118
iris %>% filter(Sepal.Length > 5) %>% nrow()
[1] 118
Try making a histogram of the Sepal.Width
parameter again and change the label on the x-axis. Go to the ggplot2
reference site (https://ggplot2.tidyverse.org/reference/index.html), find the reference for geom_histogram()
, and figure out how to change the x-axis label.
When you’ve done this, give your plot a title.
Exercise 1.2
Make a scatterplot of two variables in the iris dataset. If you don’t know what ggplot function to use for this, try searching in Google.
When you’ve done this, try coloring the points in the scatterplot by the Species
variable.
Exercise 1.3
Make a new variable in iris
that is a the difference between the Sepal.Width
and Petal.Length
variables, and call it Length.Diff
. Hint: use the mutate()
function.
Exercise 1.4
Try making a linear regression between two of the measurement variables using lm()
. Try experimenting the model, adding more variables and interactions between variables.
LS0tCnRpdGxlOiAiRXhlcmNpc2UgMSIKb3V0cHV0OiBodG1sX25vdGVib29rCi0tLQoKIyBFeGVyY2lzZSAxLjEKCkxldCdzIGxvYWQgdGhlIGlyaXMgZGF0YXNldCBhZ2Fpbi4KCmBgYHtyfQpkYXRhKCJpcmlzIikKYGBgCgpSZW1lbWJlciB0aGF0IHRoZXJlIG9mdGVuIG1hbnkgd2F5cyB0byBzb2x2ZSB0aGUgc2FtZSBwcm9ibGVtLiBUaGUgdGhyZWUgbGluZXMgb2YgY29kZSBiZWxvdyBwcm9kdWNlIHRoZSBzYW1lIHJlc3VsdCBpbiB0aHJlZSBkaWZmZXJlbnQgd2F5cy4KCmBgYHtyfQpzdW0oaXJpcyRTZXBhbC5MZW5ndGggPiA1KQppcmlzICU+JSBzdW1tYXJpemUoc3VtKFNlcGFsLkxlbmd0aCA+IDUpKSAlPiUgcHVsbCgpCmlyaXMgJT4lIGZpbHRlcihTZXBhbC5MZW5ndGggPiA1KSAlPiUgbnJvdygpCmBgYAoKVHJ5IG1ha2luZyBhIG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