Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to create a basic scatter plot using ggplot2.
R Programming
library(ggplot2)
ggplot(mtcars, aes(x = wt, y = mpg)) + geom_[1]() Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'scatter' instead of 'point' inside geom_ function.
✗ Incorrect
The correct function to add points in ggplot2 is geom_point().
2fill in blank
mediumComplete the code to add a title to the plot.
R Programming
ggplot(mtcars, aes(x = wt, y = mpg)) + geom_point() + ggtitle([1]) Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Forgetting to put quotes around the title text.
✗ Incorrect
The title text must be a string, so it needs to be in quotes like "mpg vs wt".
3fill in blank
hardFix the error in the code to change the color of points to blue.
R Programming
ggplot(mtcars, aes(x = wt, y = mpg)) + geom_point(color = [1]) Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using color names without quotes causes errors.
✗ Incorrect
Colors in ggplot2 must be specified as strings, so use "blue".
4fill in blank
hardFill both blanks to customize the plot with a theme and axis labels.
R Programming
ggplot(mtcars, aes(x = wt, y = mpg)) + geom_point(color = "blue") + [1]() + [2](title = "Car Data", x = "Weight", y = "Miles per Gallon")
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using
labels() instead of labs().✗ Incorrect
theme_minimal() applies a clean theme, and labs() sets axis labels and title.
5fill in blank
hardFill all three blanks to create a customized scatter plot with color, size, and theme.
R Programming
ggplot(mtcars, aes(x = wt, y = mpg, color = [1], size = [2])) + geom_point() + [3]()
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Quoting variable names for color and size aesthetics.
✗ Incorrect
Color is mapped to the number of cylinders (cyl), size to horsepower (hp), and theme_light() applies a light theme.