When I use aes(fill=...)
to indicate factor levels in a geom_dotplot
, points of different factor levels overlap each other. Especially with large datasets, this becomes troublesome.
Below I have included a minimal example and figure, in which I first plot a dataset without colouring factor levels, and then I add fill
to indicate factor levels, which leads to points overlapping each other. How can I avoid this?
I am aware of a similar question here; however, the answers given do not resolve this issue.
library("ggplot2")
n <- 200
x <- data.frame(x = sample(x = letters[1:3], size = n, replace = TRUE),
y = rnorm(n = n, mean = 0, sd = 1),
a = sample(x = letters[4:5], size = n, replace = TRUE))
p1 <- ggplot(x, aes(x = x, y = y))
p1 <- p1 + geom_dotplot(binaxis = "y", stackdir = "center")
p2 <- ggplot(x, aes(x = x, y = y, fill = a))
p2 <- p2 + geom_dotplot(binaxis = "y", stackdir = "center")