Draw a boxplot of
hwyfor each value of
cyl, without turning
cylinto a factor. What extra aesthetic do you need to set?
Modify the following plot so that you get one boxplot per integer value of
ggplot(mpg, aes(displ, cty)) + geom_boxplot()
When illustrating the difference between mapping continuous and discrete colours to a line, the discrete example needed
aes(group = 1). Why? What happens if that is omitted? What’s the difference between
aes(group = 1)and
aes(group = 2)? Why?
How many bars are in each of the following plots?
ggplot(mpg, aes(drv)) + geom_bar() ggplot(mpg, aes(drv, fill = hwy, group = hwy)) + geom_bar() library(dplyr) mpg %>% arrange(hwy) %>% mutate(id = seq_along(hwy)) mpg2 <-ggplot(mpg2, aes(drv, fill = hwy, group = id)) + geom_bar()
(Hint: try adding an outline around each bar with
colour = "white")
Install the babynames package. It contains data about the popularity of babynames in the US. Run the following code and fix the resulting graph. Why does this graph make me unhappy?
library(babynames) dplyr::filter(babynames, name == "Hadley") hadley <-ggplot(hadley, aes(year, n)) + geom_line()