d1 <- data.frame(x = runif(n = 10000, min = 0, max = 1), y =
rnorm(10000, sd = 0.2), type = "d1")
d2 <- data.frame(x = runif(n = 10000, min = 0, max = 1), y =
rnorm(10000, mean = 0.2, sd = 0.2), type = "d2")
all_d <- rbind(d1, d2)
ggplot(all_d, aes(x = x, y = y, color = type)) + geom_point()

Here you can see that the points are d2
displayed by points d1
. So I'm trying to make a difference usingforcats::fct_relevel
all_d_other <- all_d
all_d_other$type <- forcats::fct_relevel(all_d_other$type, "d2", "d1")
ggplot(all_d_other, aes(x = x, y = y, color = type)) + geom_point()

And the d2
dots are still on top of the dots d1
. Is there a way to change it so that the points d1
are on top of the points d2
?
source
share