program 12

Author

varsha gb-1NT23IS243-D

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

library(ggplot2)

step 2: Grouping variables

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