Starting from:

$34.99

CSCI297B Exercise 10- facets Solution

For this project, use the tidyverse library, which includes the mpg dataset.
For this project, you will turn in a single R markdown file, called exercise10.Rmd
1. What happens if you facet on a continuous variable?
2. What do the empty cells in plot with facet_grid(drv ~ cyl) mean? Run the following code. How do they relate to the resulting plot?
ggplot(mpg) + geom_point(aes(x = drv, y = cyl))
3. What plots does the following code make? What does . do?
ggplot(mpg) +
geom_point(aes(x = displ, y = hwy)) + facet_grid(drv ~ .)
ggplot(mpg) +
geom_point(aes(x = displ, y = hwy)) + facet_grid(. ~ cyl)
4. Take the first faceted plot in this section:
ggplot(mpg) +
geom_point(aes(x = displ, y = hwy)) + facet_wrap(~ class, nrow = 2)
What are the advantages to using faceting instead of the color aesthetic? What are the disadvantages? How might the balance change if you had a larger dataset?
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?
1
6. Which of the following plots makes it easier to compare engine size (displ) across carswith different drive trains? What does this say about when to place a faceting variable across rows or columns?
ggplot(mpg, aes(x = displ)) +
geom_histogram() + facet_grid(drv ~ .)
ggplot(mpg, aes(x = displ)) +
geom_histogram() + facet_grid(. ~ drv)
7. Recreate the following plot using facet_wrap() instead of facet_grid(). How do the positions of the facet labels change?
ggplot(mpg) +
geom_point(aes(x = displ, y = hwy)) + facet_grid(drv ~ .)
2

More products