0
0
R Programmingprogramming~10 mins

Grammar of Graphics concept 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 basic scatter plot using ggplot2.

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
Bbar
Cscatter
Dline
Attempts:
3 left
💡 Hint
Common Mistakes
Using geom_bar() or geom_line() instead of geom_point()
2fill in blank
medium

Complete the code to map the color aesthetic to the variable 'cyl' in the plot.

R Programming
ggplot(mtcars, aes(x = wt, y = mpg, color = [1])) + geom_point()
Drag options to blanks, or click blank then click option'
Agear
Bwt
Ccyl
Dmpg
Attempts:
3 left
💡 Hint
Common Mistakes
Mapping color to continuous variables like 'wt' or 'mpg' without intention
3fill in blank
hard

Fix the error in the code to add a title to the plot using ggtitle().

R Programming
ggplot(mtcars, aes(x = wt, y = mpg)) + geom_point() + ggtitle([1])
Drag options to blanks, or click blank then click option'
Ampg vs wt
B"mpg vs wt"
Cmpg_vs_wt
Dmpg_vs_wt()
Attempts:
3 left
💡 Hint
Common Mistakes
Not using quotes around the title text
4fill in blank
hard

Fill both blanks to create a histogram of 'mpg' with blue fill color.

R Programming
ggplot(mtcars, aes(x = [1])) + geom_histogram(fill = [2])
Drag options to blanks, or click blank then click option'
Ampg
B"blue"
Cwt
D"red"
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong variable for x or missing quotes around color
5fill in blank
hard

Fill all three blanks to create a boxplot of 'mpg' grouped by 'cyl' with green boxes and a title.

R Programming
ggplot(mtcars, aes(x = [1], y = [2])) + geom_boxplot(fill = [3]) + ggtitle("MPG by Cylinders")
Drag options to blanks, or click blank then click option'
Acyl
Bmpg
C"green"
Dwt
Attempts:
3 left
💡 Hint
Common Mistakes
Swapping x and y variables or missing quotes around color