Program_12

Author

Anusha Y K

###Program: Develop a script in R to create a violin plot displaying the distribution of a continuous variable, with separate violins for each group, using ggplot2.

1. Load the necessary library

library(ggplot2)

2. Use a built-in dataset (iris)

Species is the grouping variable, Sepal.Length is the continuous variable

data <- iris

3. Create the plot

violin_plot <- ggplot(data, aes(x = Species, y = Sepal.Length, fill = Species)) + 
  geom_violin(trim = FALSE, alpha = 0.7) +
  geom_boxplot(width = 0.1, color = "black", outlier.shape = NA) +
  labs(
    title = "Distribution of Sepal Length by Species",
    x = "Plant Species",
    y = "Sepal Length (cm)"
  ) +
  theme_minimal() +
  theme(legend.position = "none")

4. Display the plot

print(violin_plot)