Is there an automatic way to keep the legend in graph with one line which was created with ggplot2 and then converted to plotly graph through ggplotly, subplot or similar function?
And why are this kind of labels labels removed?
Illustration of my concerns:
several_lines <- {ggplot(iris, aes(x = Sepal.Length, y = Sepal.Width, color = Species)) + geom_line()} %>%
ggplotly() %>%
layout(showlegend = TRUE) %>% plotly_build()
iris$All <- "All species"
one_line <- {ggplot(iris, aes(x = Sepal.Length, y = Sepal.Width, color = All)) + geom_line()} %>%
ggplotly() %>%
layout(showlegend = TRUE) %>% plotly_build()
Legend is displayed:
Legend is missing:
Even the text of the legend entry is missing:
one_line$data[[1]]$name
## [1] ""
one_line$data[[1]]$showlegend
## [1] FALSE