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 variables
$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()