I am generating ECDF plots using the stat_ecdf command from ggplot2. I would like to be able to specify colours for points in the ecdf with different categories.
We'll use the iris dataset as a toy example. When I attempt to use aes(col=Species) in stat_ecdf the plot is split into the three separate ecdfs rather than simply colouring the individual points. For example:
library(ggplot2)
ggplot(iris) +
stat_ecdf(aes(x = Sepal.Length,
col = Species),
geom = "point")
I managed to create my desired output using both the ecdf and geom_point like so:
ggplot(data = data.frame(
value = iris$Sepal.Length,
ecdf = ecdf(iris$Sepal.Length)(iris$Sepal.Length),
spec = iris$Species
)) +
geom_point(aes(x = value, y = ecdf, col = spec))
My question is: is it possible to produce the second graph using the stat_ecdf function?

