program12

Author

Swathi_1nt23is228

Develop a script in R to create a violin plot displaying the distribution of a continous variable with a separate violins for each group using ggplot2.

Step1- load the library

library(ggplot2)

Step2- Create the violin plot

violin_plot <- ggplot(data = iris, aes(x = Species, y = Sepal.Length, fill = Species)) +
  geom_violin(trim = FALSE) +  # Show full distribution without trimming tails
  geom_boxplot(width = 0.1, fill = "white") +  # Add a boxplot inside violins
  labs(title = "Distribution of Sepal Length by Species",
       x = "Species",
       y = "Sepal Length") +
  theme_minimal() +
  theme(legend.position = "none")

Step3- Display the plot

print(violin_plot)