0
0
R Programmingprogramming~10 mins

Why ggplot2 creates publication-quality graphics in R Programming - Test Your Understanding

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

Complete the code to create a basic ggplot2 scatter plot.

R Programming
library(ggplot2)
ggplot(data = mtcars, aes(x = wt, y = mpg)) + geom_[1]()
Drag options to blanks, or click blank then click option'
Apoint
Bpoints
Cscatter
Dgeom_point
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'scatter' instead of 'point' in the geom function.
Using 'geom_point' without parentheses.
Using 'geom_point' instead of 'point'.
2fill in blank
medium

Complete the code to add a title to the ggplot2 plot.

R Programming
ggplot(data = mtcars, aes(x = wt, y = mpg)) + geom_point() + ggtitle([1])
Drag options to blanks, or click blank then click option'
AMy Plot
B'My Plot'
C"My Plot"
DMy_Plot
Attempts:
3 left
💡 Hint
Common Mistakes
Not using quotes around the title string.
Using variable names without quotes.
Using single quotes inconsistently.
3fill in blank
hard

Fix the error in the code to correctly map color to the 'cyl' variable.

R Programming
ggplot(mtcars, aes(x = wt, y = mpg, color = [1])) + geom_point()
Drag options to blanks, or click blank then click option'
Acylinders
Bcyl
Cmpg
D"cyl"
Attempts:
3 left
💡 Hint
Common Mistakes
Using a non-existent variable name.
Putting the variable name in quotes inside aes().
Using a different variable like 'mpg' instead of 'cyl'.
4fill in blank
hard

Fill both blanks to create a plot with points sized by 'hp' and shaped by 'gear'.

R Programming
ggplot(mtcars, aes(x = wt, y = mpg, size = [1], shape = [2])) + geom_point()
Drag options to blanks, or click blank then click option'
Ahp
Bgear
Ccyl
Dmpg
Attempts:
3 left
💡 Hint
Common Mistakes
Mixing up size and shape variables.
Using variables not in the dataset.
Putting variable names in quotes inside aes().
5fill in blank
hard

Fill all three blanks to create a plot with customized labels and theme.

R Programming
ggplot(mtcars, aes(x = [1], y = [2])) + geom_point() + labs(title = [3]) + theme_minimal()
Drag options to blanks, or click blank then click option'
Awt
Bmpg
C"Fuel Efficiency vs Weight"
Dhp
Attempts:
3 left
💡 Hint
Common Mistakes
Swapping x and y variables.
Not quoting the title string.
Using variables not related to the plot.