Ggplotly removes legend from ggplot

ggplotly removes the geom_line graphic legend using ggplot.

See below:

library(plotly)    
g <- ggplot(iris)
g = g + geom_line(aes(x = Sepal.Length, y = Sepal.Width, color = Species), size = 0.05)
g # Here is a legend
(gg <- ggplotly(g)) # Legend has now been removed.

Any ideas on how to bring back the legend?

I am using plotly_2.0.19 and ggplot2_2.0.0.9.9000.

+4
source share
1 answer

For some reason, ggplotlynever adds a legend for geom_line. There are only legends in the documentation when points are added. I suggest using transparent dots as work.

{ ggplot(iris, aes(x = Sepal.Length, y = Sepal.Width, color = Species)) +
  geom_line() +
  geom_point(alpha = 0) } %>%
  ggplotly()

enter image description here

+5
source

Source: https://habr.com/ru/post/1622911/


All Articles