Program-13

Author

Vaishnavi

program -13 Write an R program to create multiple dot plots for grouped data, comparing the distributions of variables across different categories, using ggplot2’s position_dodge function

library(ggplot2)
library(tidyr)
data <- ToothGrowth
data$dose <- as.factor(data$dose)
ggplot(data, aes(x = dose, y = len, fill = supp)) +
  geom_dotplot(
    binaxis = "y",
    stackdir = "center",
    dotsize = 0.7,
    position = position_dodge(width = 0.9)
  ) +
  facet_wrap(~ supp) +
  labs(
    title = "Grouped Dot Plots of Tooth Growth",
    x = "Dose (mg)",
    y = "Tooth Length",
    fill = "Supplement"
  ) +
  theme_minimal()
Bin width defaults to 1/30 of the range of the data. Pick better value with
`binwidth`.