0
0
R Programmingprogramming~20 mins

Grammar of Graphics concept in R Programming - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Grammar of Graphics Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2:00remaining
What is the output of this ggplot2 code?
Consider the following R code using ggplot2. What will be the output when this code runs?
R Programming
library(ggplot2)
data <- data.frame(x = 1:3, y = c(3, 2, 1))
ggplot(data, aes(x = x, y = y)) + geom_point() + geom_line()
AA histogram of y values
BA bar chart showing counts of x values
CA scatter plot with points connected by lines in order of x values
DA boxplot of y grouped by x
Attempts:
2 left
💡 Hint
Think about what geom_point() and geom_line() do in ggplot2.
🧠 Conceptual
intermediate
1:30remaining
Which component of Grammar of Graphics defines how data variables map to visual properties?
In the Grammar of Graphics, which component describes the mapping of data variables to visual aesthetics like color, size, or position?
AAesthetics
BStatistics
CGeoms
DFacets
Attempts:
2 left
💡 Hint
Think about what controls the look of points or lines based on data.
🔧 Debug
advanced
2:00remaining
What error does this ggplot2 code produce?
Examine the code below. What error will it raise when run?
R Programming
library(ggplot2)
data <- data.frame(x = 1:5, y = c(2, 4, 6, 8, 10))
ggplot(data, aes(x = x, y = y)) + geom_point() + geom_line(aes(color = z))
ANo error, plot displays with default color
BError: geom_line() requires a numeric y aesthetic
CError: geom_point() missing required aesthetics
DError: object 'z' not found
Attempts:
2 left
💡 Hint
Check if all variables used in aes() exist in the data frame.
📝 Syntax
advanced
1:30remaining
Which option correctly adds a title to a ggplot?
Which of the following R code snippets correctly adds the title 'My Plot' to a ggplot object named p?
Ap + ggtitle('My Plot')
Bp + title('My Plot')
Cp + labs(title = 'My Plot')
Dp + set_title('My Plot')
Attempts:
2 left
💡 Hint
ggplot2 uses specific functions to add titles and labels.
🚀 Application
expert
2:30remaining
How many layers does this ggplot have?
Given the code below, how many layers are added to the ggplot object?
R Programming
library(ggplot2)
data <- data.frame(x = 1:4, y = c(4, 3, 2, 1))
p <- ggplot(data, aes(x, y)) + geom_point() + geom_smooth(method = 'lm') + facet_wrap(~x)
A3
B2
C4
D1
Attempts:
2 left
💡 Hint
Count only the layers that add visual elements, not facets.