library(ggplot2)program 12
12 Develop a script in R to create a violin plot displaying the distribution of a continuous variable , with a separate violins for each group using an inbuilt dataset.
Step 1: Load the library
Step 2: Grouping variable
mtcars$cyl <- as.factor(mtcars$cyl)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()