0
0
R Programmingprogramming~10 mins

ggplot() and aes() basics 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 ggplot object with the data frame 'df'.

R Programming
p <- ggplot([1])
Drag options to blanks, or click blank then click option'
Adf
Bgeom_point()
Caes
Dggplot
Attempts:
3 left
💡 Hint
Common Mistakes
Using aes or geom_point() directly inside ggplot() without specifying data.
Passing the function ggplot itself as argument.
2fill in blank
medium

Complete the code to map the variable 'x_var' to the x-axis inside aes().

R Programming
p <- ggplot(df, aes(x = [1]))
Drag options to blanks, or click blank then click option'
Ax_var
Bgeom_point
Cdf
Dy_var
Attempts:
3 left
💡 Hint
Common Mistakes
Using a variable name that is not in the data frame.
Passing the whole data frame instead of a variable name.
3fill in blank
hard

Fix the error in the code by completing the aes() mapping for both x and y variables.

R Programming
p <- ggplot(df, aes(x = [1], y = [2])) + geom_point()
Drag options to blanks, or click blank then click option'
Ax_var
Bgeom_point
Cy_var
Ddf
Attempts:
3 left
💡 Hint
Common Mistakes
Using geom_point inside aes().
Using the data frame name instead of variable names.
4fill in blank
hard

Fill both blanks to create a scatter plot mapping 'height' to x and 'weight' to y.

R Programming
p <- ggplot(data = df, aes(x = [1], y = [2])) + geom_point()
Drag options to blanks, or click blank then click option'
Aheight
Bweight
Cage
Dgender
Attempts:
3 left
💡 Hint
Common Mistakes
Swapping the variables for x and y.
Using variables not present in the data frame.
5fill in blank
hard

Fill all three blanks to create a ggplot with data 'df', mapping 'age' to x, 'income' to y, and adding points.

R Programming
p <- ggplot([1], aes(x = [2], y = [3])) + geom_point()
Drag options to blanks, or click blank then click option'
Adf
Bage
Cincome
Dheight
Attempts:
3 left
💡 Hint
Common Mistakes
Using variable names outside of aes().
Mixing up the order of arguments.