Bug with ggplot2 stat_ecdf() function

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:
library(ggplot2)
library(plotly)

# 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) ) +
    stat_ecdf())
# but ggplotly messes it up
ggplotly(gg)

https://trickytank.github.io/webhelp/plotly/ecdf_animals_broken.html

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

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

https://trickytank.github.io/webhelp/plotly/ecdf_animals_working.html