Exercise 3.5.1

Boredom Exercise

install.packages('tidyverse')
## Installing package into '/home/rstudio-user/R/x86_64-pc-linux-gnu-library/3.6'
## (as 'lib' is unspecified)
library(tidyverse)
## ── Attaching packages ───────────────────────────────── tidyverse 1.3.0 ──
## ✓ ggplot2 3.3.0     ✓ purrr   0.3.4
## ✓ tibble  3.0.1     ✓ dplyr   0.8.5
## ✓ tidyr   1.0.3     ✓ stringr 1.4.0
## ✓ readr   1.3.1     ✓ forcats 0.5.0
## ── Conflicts ──────────────────────────────────── tidyverse_conflicts() ──
## x dplyr::filter() masks stats::filter()
## x dplyr::lag()    masks stats::lag()
Question 1: What happens if you facet on a continuous variable?

We try to put ‘displ’ (a continuous variable) on facet

ggplot(data = mpg) + 
  geom_point(mapping = aes(x = cyl, y = hwy), col ='red') +
  facet_wrap(~ displ)

Question 2: What do the empty cells in plot with facet_grid(drv ~ cyl) mean? How do they relate to this plot?
ggplot(data = mpg) + 
  geom_point(mapping = aes(x = displ, y = hwy), col = 'pink') +
  facet_grid(drv ~ cyl)

Question 3: What plots does the following code make? What does . do?
ggplot(data = mpg) + 
  geom_point(mapping = aes(x = displ, y = hwy), col = 'blue') +
  facet_grid(drv ~ .)

ggplot(data = mpg) + 
  geom_point(mapping = aes(x = displ, y = hwy), col = 'blue') +
  facet_grid(. ~ cyl)

Question 4: Take the first faceted plot in this section:
ggplot(data = mpg) + 
  geom_point(mapping = aes(x = displ, y = hwy, color = class), col = 'yellow')

ggplot(data = mpg) + 
  geom_point(mapping = aes(x = displ, y = hwy), col = 'orange') + 
  facet_wrap(~ class, nrow = 2)

Question 5: Read ?facet_wrap. What does nrow do? What does ncol do? What other options control the layout of the individual panels? Why doesn’t facet_grid() have nrow and ncol arguments?
?facet_wrap
Question 6: When using facet_grid() you should usually put the variable with more unique levels in the columns. Why?
ggplot(data = mpg) + 
  geom_point(mapping = aes(x = displ, y = hwy), col = 'red') + 
  facet_grid(class ~ drv)

Quarantine Exercise