Program 12

Author

Greeshma PM(1nt23is078)Section-B

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

library(ggplot2)

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