Complete the code to create a scatter plot with facets by the variable 'cyl'.
library(ggplot2)
ggplot(mtcars, aes(x = wt, y = mpg)) + geom_point() + facet_[1](~ cyl)The facet_wrap function creates subplots (facets) wrapped by the variable specified.
Complete the code to facet the plot by 'cyl' and 'gear' using a grid layout.
ggplot(mtcars, aes(x = wt, y = mpg)) + geom_point() + facet_grid([1] ~ [2])
facet_grid takes two variables separated by ~ to create a grid of subplots by rows and columns.
Fix the error in the code to facet by 'cyl' using facet_wrap.
ggplot(mtcars, aes(x = wt, y = mpg)) + geom_point() + facet_wrap(~ [1])The variable name must exactly match the dataset column. 'cyl' is correct; 'cyls' is not a column.
Fill both blanks to facet the plot by 'cyl' in rows and 'am' in columns.
ggplot(mtcars, aes(x = hp, y = mpg)) + geom_point() + facet_grid([1] ~ [2])
facet_grid uses the first variable for rows and the second for columns. Here, 'cyl' is rows and 'am' is columns.
Fill all three blanks to create a faceted plot with 'cyl' wrapped, color by 'gear', and size by 'hp'.
ggplot(mtcars, aes(x = wt, y = mpg, color = [1], size = [2])) + geom_point() + facet_wrap(~ [3])
The color aesthetic is set to 'gear', size to 'hp', and faceting is done by 'cyl' using facet_wrap.