library(ggplot2)
Program 12
Develop a script in R to create a violin plot displaying the distribution of a continuous variable, with separate violins, using ggplot2.
Step 1:Load the library
Step 2: Grouping variable
$cyl <- as.factor(mtcars$cyl) mtcars
Step 3: Create a violin plot
ggplot(mtcars, aes(x=cyl, y= mpg, fill = cyl)) +
geom_violin(trim=FALSE)+
labs(
title= "Distribution of MPG by Number of Cylinders",
x= "Number of cylinders",
y= "Miles Per Gallon (MPG)"
+
) theme_minimal()