I use geom_dotplot and I want to distinguish by color which points are in one group compared to another. I successfully did this by adding "fill = group" to aes () in geom_dotplot ().
Here is a sample code that reproduces the error:
set.seed(124)
df <- data.frame(Group = rep(c("control","treatment"),20), Response = sample(1:10,40, replace = T), Recovered = rep(c("no","no","no","no","yes"),4))
ggplot() + geom_dotplot(data = df, aes(x = Group, y = Response, fill = Recovered),binaxis = "y", stackdir = "center", alpha = 0.3) + coord_flip()
However, now the package no longer adds points in the same group next to each other, but overlaps them, hiding some data.
I can set alpha = 0.5 to see where this overlap is, but I would prefer it to plot all the points next to each other and just color some of the points. Does anyone know how to do this?
I know that I can set position_dodge to a small amount, but would prefer that it does not contradict the interpretation of the axis.
Edit: dput (df) output:
structure(list(Group = structure(c(1L, 2L, 1L, 2L, 1L, 2L, 1L,
2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L,
2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L,
2L), .Label = c("control", "treatment"), class = "factor"), Response = c(1L,
5L, 6L, 4L, 3L, 3L, 6L, 5L, 10L, 3L, 8L, 9L, 8L, 9L, 5L, 1L,
6L, 8L, 9L, 1L, 7L, 7L, 1L, 5L, 4L, 3L, 9L, 3L, 9L, 4L, 9L, 4L,
5L, 9L, 2L, 10L, 2L, 10L, 2L, 4L), Recovered = structure(c(1L,
1L, 1L, 1L, 2L, 1L, 1L, 1L, 1L, 2L, 1L, 1L, 1L, 1L, 2L, 1L, 1L,
1L, 1L, 2L, 1L, 1L, 1L, 1L, 2L, 1L, 1L, 1L, 1L, 2L, 1L, 1L, 1L,
1L, 2L, 1L, 1L, 1L, 1L, 2L), class = "factor", .Label = c("no",
"yes"))), .Names = c("Group", "Response", "Recovered"), row.names = c(NA,
-40L), class = "data.frame")