Challenge - 5 Problems
Scatter Plot Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2:00remaining
Output of basic scatter plot code
What will be the output of this R code using ggplot2?
R Programming
library(ggplot2) data <- data.frame(x = 1:5, y = c(2, 3, 5, 7, 11)) ggplot(data, aes(x = x, y = y)) + geom_point()
Attempts:
2 left
💡 Hint
geom_point() creates scatter plots by plotting points at given x and y coordinates.
✗ Incorrect
The code uses ggplot2 to plot points at the specified x and y values. geom_point() adds points, not lines or bars.
🧠 Conceptual
intermediate1:30remaining
Understanding aesthetics in geom_point
Which option correctly describes the role of the aes() function inside ggplot() when creating a scatter plot with geom_point()?
Attempts:
2 left
💡 Hint
Think about what aes() does with data variables in ggplot2.
✗ Incorrect
aes() maps data variables to visual aesthetics like x, y, color, size, shape, etc. It does not control plot size or labels.
🔧 Debug
advanced2:00remaining
Identify the error in this scatter plot code
What error will this R code produce?
R Programming
library(ggplot2) data <- data.frame(x = 1:3, y = c(4, 5, 6)) ggplot(data, aes(x = x, y = y)) + geom_point(color = "blue")
Attempts:
2 left
💡 Hint
Check if all parentheses are properly closed.
✗ Incorrect
The original code was missing a closing parenthesis after geom_point(color = "blue"), causing a syntax error. The corrected code includes the closing parenthesis.
❓ Predict Output
advanced2:30remaining
Effect of mapping color inside aes() vs outside
What is the difference in output between these two ggplot2 codes?
R Programming
library(ggplot2) data <- data.frame(x = 1:4, y = c(2, 4, 6, 8), group = c('A', 'B', 'A', 'B')) # Code 1: ggplot(data, aes(x = x, y = y, color = group)) + geom_point() # Code 2: ggplot(data, aes(x = x, y = y)) + geom_point(color = 'red')
Attempts:
2 left
💡 Hint
aes() maps data variables to aesthetics; setting color outside aes() applies a fixed color.
✗ Incorrect
In Code 1, color is mapped to the group variable, so points get different colors by group. In Code 2, color is fixed to red for all points.
🚀 Application
expert2:30remaining
Count of points plotted with filtering in geom_point
Given this code, how many points will be shown in the scatter plot?
R Programming
library(ggplot2) data <- data.frame(x = 1:6, y = c(3, 5, 7, 9, 11, 13)) ggplot(data, aes(x = x, y = y)) + geom_point(data = subset(data, y > 7))
Attempts:
2 left
💡 Hint
Look at the subset condition y > 7 and count how many rows satisfy it.
✗ Incorrect
Only points with y values greater than 7 are plotted. y values are 3,5,7,9,11,13 so points with y=9,11,13 qualify (3 points).