Write an r program to create multiple dot plots for grouped data comparing the distributions of variables across different categories using ggplot2 lib.
Objective
To create multiple dot plots for grouped data and compare the distribution of tooth length across different supplement types and dosage levels using ggplot2 and dplyr.
Step 1: Load required packages
We use ggplot2 for visualization and dplyr for data manipulation.
#install.packages("ggplot2") # Uncomment if needed#install.packages("dplyr") # Uncomment if neededlibrary(ggplot2)
Warning: package 'ggplot2' was built under R version 4.5.3
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: Use an inbuilt dataset
We will use the built-in ToothGrowth dataset. It contains:
# len → Tooth length# supp → Supplement type (VC or OJ)# dose → Dosage level# Load and preview datasetdata(ToothGrowth)head(ToothGrowth)