Skip to content

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

Closed
@GegznaV

Description

@GegznaV

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions