PRG 13 DV

Author

ANUSHA

PROGRAM 13

Write an R program to create a multiple dot plot or grouped data compairing the distance of variables across different categories using ggplot2’s position_dodgefunction.

step 1:- load the required library

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:-convert dose to factor

# Convert dose to a factor
ToothGrowth$dose <- as.factor(ToothGrowth$dose)

# Load ggplot2
library(ggplot2)

# Create the dot plot
ggplot(ToothGrowth, aes(x = dose, y = len, color = supp)) +
  geom_dotplot(
    binaxis = "y",
    stackdir = "center",
    dotsize = 0.6,
    position = position_dodge(0.8),
    binwidth = 1.5
  ) +
  labs(
    title = "Tooth Growth by Supplement Type and Dose",
    x = "Dose (mg)",
    y = "Tooth Length"
  ) +
  theme_minimal()