Program-13

Author

Kaushik

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

Step 1: Load the libraries

library(ggplot2)
library(dplyr)

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

Step 2: Create multiple dot plots

ToothGrowth$dose<- as.factor(ToothGrowth$dose)
ggplot(ToothGrowth,aes(x=dose, y=len, color=supp))+
  geom_dotplot(
  position = position_dodge(width = 0.7),
  binwidth = 1.6,
  binaxis = "y",
  stackdir = "center",
  dotsize = 0.8,
  width = 0.9
  )+
  labs(
    title = "Dot Plot of Tooth Length by Dose and Supplement Type",
    x="Dose (mg/day)",
    y="Tooth Length",
    color="Supplement Type"
  )+
theme_minimal()