Black Lives Matter. Please consider donating to Black Girls Code today.
Learn how to use COVID-19 data in open source Dash apps. Register for the Sept 23rd webinar with IQT!

Bug with ggplot2 stat_ecdf() function

When I try to display a ecdf ggplot, it seems that plotly doesn’t work.

With any data (I think), when doing :
ecdf=ggplot(rg, aes(RR)) + stat_ecdf()

It is OK to see the graphic. However ggplotly(ecdf) will display a very different plot.

I’m having the same issue. Have you alredy solved it?

I scratched my head over this for a while. A hack fix is to sort the data.frame by the observation.

I have provided code to demonstrate this fix:

# Set up
animals <- c("duck", "llama", "python")
n <- 50
animals_sd <- seq_along(animals)^2
a <- data.frame(anim = rep(animals, each = n), size = rpois(length(animals) * n, rep(animals_sd, each = n)))

# Works fine in ggplot2
(gg <- ggplot(a, aes(x = size, colour = anim) ) +
# but ggplotly messes it up

# This can be fixed by sorting by the x aesthetic:
b <- a[order(a$size), ]

(gg_sort <- ggplot(b, aes(x = size, colour = anim) ) +

I really think it still looks better with the normal R plot