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
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(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
$dose <- as.factor(ToothGrowth$dose)
ToothGrowthggplot(ToothGrowth, aes(x = dose, y = len, color = supp)) +
geom_dotplot(
binaxis = 'y', # to assign to which axis
stackdir = 'center',
position = position_dodge(width = 0.8),
dotsize = 0.6,
binwidth = 1.5 # it gives the spacing between the dots
+
) labs(
title = "Dot Plot of Tooth Length by Dose and Supplement type",
x = "Dose ",
y = "Tooth Length",
color = "Supplement Type"
+
) theme_minimal()