Skip to content

When using ggplotly() there can be duplication of legend items inconsistent with ggplot output #2043

Closed
@wphampton

Description

@wphampton

Thank you for this fantastic package -- I am amazed how well it works!

When multiple geom_line() or geom_point() entries exist, the ggplotly() output can be different from the ggplot() output. What I've noticed is duplication of legend entries and sometimes ignoring of legend configuration options that ggplot provides.

Seems possibly related to #572 & #2010

df1 <- data.frame(
  "Date" = seq(as.Date("2021-01-01"), as.Date("2021-01-10"), "days"),
  "Series" = c(rep("SeriesA", 10), rep("SeriesB",10)),
  "Values" = rnorm(n = 20),
  "Mean" = 0,
  "V1" = 2,
  "V2" = -2
)

p <- ggplot(df1, aes(x=Date, y=Values, color = Series, linetype = Series, shape = Series)) +
  geom_line(aes(x = Date, y = Mean, color = "Mean", linetype = "Mean")) +
  geom_line(aes(x = Date, y = V1, color = "QC", linetype = "QC")) +
  geom_line(aes(x = Date, y = V2, color = "QC", linetype = "QC")) +
  geom_line() + 
  geom_point() + 
  guides(shape=FALSE, linetype=FALSE)

ggplotly(p)

ggplot() Output

image

ggplotly() Output

image

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