Complete the code to create a basic box plot of the variable 'mpg' from the 'mtcars' dataset.
boxplot(mtcars$[1])The boxplot function requires the variable name to plot. Here, 'mpg' is the variable representing miles per gallon.
Complete the code to create a violin plot of 'mpg' grouped by 'cyl' using ggplot2.
library(ggplot2)
ggplot(mtcars, aes(x = factor([1]), y = mpg)) + geom_violin()To group the violin plot by the number of cylinders, we use 'cyl' as the x-axis variable, converted to a factor for categorical grouping.
Fix the error in the code to add a box plot layer to a ggplot object 'p' that plots 'mpg' by 'cyl'.
p + geom_boxplot(aes([1] = factor(cyl), y = mpg))The x aesthetic should be mapped to the grouping variable 'factor(cyl)' to create separate boxes for each cylinder group.
Fill both blanks to create a combined violin and box plot of 'mpg' grouped by 'cyl' with ggplot2.
ggplot(mtcars, aes(x = factor([1]), y = mpg)) + geom_violin() + geom_[2]()
The x-axis groups by 'cyl' and the second layer adds a box plot with geom_boxplot().
Fill all three blanks to create a violin plot with customized fill color by 'cyl' and add box plot overlay.
ggplot(mtcars, aes(x = factor([1]), y = mpg, fill = factor([2]))) + geom_violin() + geom_[3](width = 0.1)
Both x and fill aesthetics use 'cyl' as a factor to group and color the plot. The box plot is added with geom_boxplot() and a narrow width for overlay.