0
0
R Programmingprogramming~10 mins

Faceting for subplots in R Programming - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to create a scatter plot with facets by the variable 'cyl'.

R Programming
library(ggplot2)
ggplot(mtcars, aes(x = wt, y = mpg)) + geom_point() + facet_[1](~ cyl)
Drag options to blanks, or click blank then click option'
Afacet
Bgrid
Cwrap
Dplot
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'facet_grid' instead of 'facet_wrap' when only one variable is used.
Misspelling the function name.
2fill in blank
medium

Complete the code to facet the plot by 'cyl' and 'gear' using a grid layout.

R Programming
ggplot(mtcars, aes(x = wt, y = mpg)) + geom_point() + facet_grid([1] ~ [2])
Drag options to blanks, or click blank then click option'
Acyl
Bgear
Cmpg
Dwt
Attempts:
3 left
💡 Hint
Common Mistakes
Swapping the order of variables.
Using variables not in the dataset.
3fill in blank
hard

Fix the error in the code to facet by 'cyl' using facet_wrap.

R Programming
ggplot(mtcars, aes(x = wt, y = mpg)) + geom_point() + facet_wrap(~ [1])
Drag options to blanks, or click blank then click option'
Agear
Bcyl
Ccyls
Dwt
Attempts:
3 left
💡 Hint
Common Mistakes
Using a variable name that does not exist in the dataset.
Adding extra characters to the variable name.
4fill in blank
hard

Fill both blanks to facet the plot by 'cyl' in rows and 'am' in columns.

R Programming
ggplot(mtcars, aes(x = hp, y = mpg)) + geom_point() + facet_grid([1] ~ [2])
Drag options to blanks, or click blank then click option'
Acyl
Bam
Cgear
Dwt
Attempts:
3 left
💡 Hint
Common Mistakes
Swapping the variables in the wrong order.
Using variables not present in the dataset.
5fill in blank
hard

Fill all three blanks to create a faceted plot with 'cyl' wrapped, color by 'gear', and size by 'hp'.

R Programming
ggplot(mtcars, aes(x = wt, y = mpg, color = [1], size = [2])) + geom_point() + facet_wrap(~ [3])
Drag options to blanks, or click blank then click option'
Agear
Bhp
Ccyl
Dam
Attempts:
3 left
💡 Hint
Common Mistakes
Mixing up the variables for color and size.
Using the wrong variable for faceting.