library(ggplot2)
data <- mtcars
data$cyl <- as.factor(data$cyl)
data$gear <- as.factor(data$gear)
ggplot(data, aes(x = cyl, y = mpg, color = gear)) +
geom_dotplot(binaxis = 'y', stackdir = 'center',
position = position_dodge(width = 0.7),
dotsize = 0.6) +
labs(title = "Dot Plot of MPG by Cylinder and Gear",
x = "Number of Cylinders",
y = "Miles Per Gallon (MPG)",
color = "Gear") +
theme_minimal()Bin width defaults to 1/30 of the range of the data. Pick better value with
`binwidth`.