Program 13

Author

Yash Pratap 1NT23IS252

Program 13

Write an R program to create multiple dot plots for grouped data, comparing the distributions of variable across different categories, using ggplot2’s position dodge function.

library(ggplot2) # package for data visualization
library(dplyr) # package for data manipulation

Attaching package: 'dplyr'
The following objects are masked from 'package:stats':

    filter, lag
The following objects are masked from 'package:base':

    intersect, setdiff, setequal, union
ToothGrowth$dose <- as.factor(ToothGrowth$dose) #making dose a factor for categorical plotting 
ggplot(ToothGrowth, aes(x = dose, y = len, color = supp)) + # mapping
  geom_dotplot(
               binaxis = "y", #plot along y axis
               stackdir = "center", 
               position = position_dodge(width = 0.8),
               dotsize = 0.6, 
               binwidth = 1.5 #vertical space btw dots 
            ) +
  labs(title = "Tooth growth",
       x = "Doses", # label 
       y = "Tooth len",
       color = "Type") +
 theme_minimal() #for better visual representation