Skip to content

ggplotly: automatic labels in graph with one line created with ggplot2 #607

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
GegznaV opened this issue May 26, 2016 · 1 comment
Closed

Comments

@GegznaV
Copy link

GegznaV commented May 26, 2016

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:

several_lines

Legend is missing:

one_line

Even the text of the legend entry is missing:

one_line$data[[1]]$name
## [1] ""

one_line$data[[1]]$showlegend
## [1] FALSE
@cpsievert
Copy link
Collaborator

Fixed in 6bd3f5b

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants