Complete the code to create a basic ggplot2 scatter plot.
library(ggplot2)
ggplot(data = mtcars, aes(x = wt, y = mpg)) + geom_[1]()The correct function to add points in ggplot2 is geom_point(). The code uses geom_point() to create a scatter plot.
Complete the code to add a title to the ggplot2 plot.
ggplot(data = mtcars, aes(x = wt, y = mpg)) + geom_point() + ggtitle([1])The title text must be a string, so it needs to be enclosed in quotes. Double quotes or single quotes work, but here double quotes are used.
Fix the error in the code to correctly map color to the 'cyl' variable.
ggplot(mtcars, aes(x = wt, y = mpg, color = [1])) + geom_point()The variable name inside aes() should be the exact column name without quotes. Here, 'cyl' is the correct variable name.
Fill both blanks to create a plot with points sized by 'hp' and shaped by 'gear'.
ggplot(mtcars, aes(x = wt, y = mpg, size = [1], shape = [2])) + geom_point()
To size points by horsepower, use 'hp'. To shape points by gear, use 'gear'. Both are column names in mtcars.
Fill all three blanks to create a plot with customized labels and theme.
ggplot(mtcars, aes(x = [1], y = [2])) + geom_point() + labs(title = [3]) + theme_minimal()
The x-axis is 'wt' (weight), y-axis is 'mpg' (miles per gallon), and the title is a string describing the plot.