Recall & Review
beginner
What is faceting in R's ggplot2?
Faceting is a way to split data into subsets and create multiple plots (subplots) arranged in a grid, each showing a subset of the data.
Click to reveal answer
beginner
Which ggplot2 function is used to create subplots by rows and columns?
The function
facet_grid() is used to create subplots arranged by rows and columns based on one or two variables.Click to reveal answer
intermediate
How does
facet_wrap() differ from facet_grid()?facet_wrap() creates subplots wrapped into multiple rows or columns based on one variable, while facet_grid() arranges subplots in a strict grid by two variables (rows and columns).Click to reveal answer
intermediate
What does the syntax
facet_grid(rows ~ cols) mean?It means subplots are arranged with the variable for rows on the left side and the variable for columns on the right side of the tilde (~). For example,
facet_grid(Species ~ .) creates rows by Species and one column.Click to reveal answer
beginner
Why use faceting instead of multiple separate plots?
Faceting helps compare subsets side-by-side in one combined plot, making patterns easier to see and saving space compared to separate plots.
Click to reveal answer
Which function in ggplot2 creates subplots arranged in a grid by two variables?
✗ Incorrect
facet_grid() arranges subplots in a grid by rows and columns based on two variables.
What does
facet_wrap(~ variable) do?✗ Incorrect
facet_wrap() splits data by one variable and wraps subplots into rows or columns.
In
facet_grid(rows ~ cols), what does the tilde (~) separate?✗ Incorrect
The tilde separates the variable for rows (left) and columns (right) in the grid layout.
Which of these is a benefit of faceting?
✗ Incorrect
Faceting helps visually compare different subsets easily by showing them side-by-side.
If you want subplots only by rows and no columns, which syntax is correct?
✗ Incorrect
facet_grid(variable ~ .) creates subplots arranged by rows only.
Explain how faceting works in ggplot2 and when you would use
facet_wrap() versus facet_grid().Think about how you want to arrange your subplots: wrapped or in a grid.
You got /4 concepts.
Describe the syntax and meaning of
facet_grid(rows ~ cols) and give an example.Remember the tilde (~) separates rows and columns variables.
You got /4 concepts.