documentation icon indicating copy to clipboard operation
documentation copied to clipboard

Issue with showlegend for add_lines

Open hlendway opened this issue 6 years ago • 0 comments

In the second example on this page, Scatterplot with Loess Smoother, add_lines has the attribute showlegend= TRUE and add markers has showlegend=FALSE, and in layout, legend = list(x = 0.80, y = 0.90), yet no legend appears. I would expect a line for the add_lines to show in the plot. I'm wondering if there's an issue? I'm struggling with something similar on a project of my own where I cannot get the legend to show for just one add_lines call.

library(plotly)
p <- plot_ly(mtcars, x = ~disp, color = I("black")) %>%
  add_markers(y = ~mpg, text = rownames(mtcars), showlegend = FALSE) %>%
  add_lines(y = ~fitted(loess(mpg ~ disp)),
            line = list(color = '#07A4B5'),
            name = "Loess Smoother", showlegend = TRUE) %>%
  layout(xaxis = list(title = 'Displacement (cu.in.)'),
         yaxis = list(title = 'Miles/(US) gallon'),
         legend = list(x = 0.80, y = 0.90))

hlendway avatar Sep 23 '19 15:09 hlendway