geom_line disappears with ggplotly

Viewed 414

I want to create an interactive line plot with three groups, together with their confidence intervals using ggplotly and highlight.

If I use three groups, the line of one group disappears from the graph.

Everything works fine if I do not use the tooltip="y" option in ggplotly, or if I do not display the errorbars.

Could someone explain me this behavior? Thanks a lot!

library(ggplot2)
library(plotly)
df <- as.data.frame(list('x'=c(1:10,1:10,1:10) , 
                         y = c(rep(-0.01,10) , rep(0,10) , rep(0.01,10)) , 
                         'ub' = rep(0,30)+0.1 , 
                         'lb' = rep(0,30)-0.1 , 
                    'gr' = c(rep("A",10) , rep("B",10) , rep("C" , 10))))

df <- highlight_key(df, ~gr)

p <- ggplot(df , aes(x=x , y = y , shape = gr , color = gr) ) +
  geom_line(size = 0.75) + 
  geom_point(size = 2  , position=position_dodge(0.2)) + 
  geom_errorbar( aes(ymin = lb , 
                     ymax = ub)
                 , width=.2 , position=position_dodge(0.2))


highlight(ggplotly(p , tooltip = "y" ) ,
          on = "plotly_click",
          off = "plotly_doubleclick",
          debounce = 200
)
0 Answers
Related