Search code examples
rggplot2ggplotlyr-plotly

ggplot : Hide geom_ribbon by default to my plot


I have this plot :

g.mean <- ggplot(df,aes(x = as.numeric(xx),y=yy,color=varc)) + 
      geom_line() +
      geom_ribbon(aes(ymin=Born_Inf, ymax=Born_Sup, fill=varc), alpha=0.1)

Is there a way to hide only geom_ribbon() and print geom_line() to my graph ? I try with "legendonly" but this hide all lines ...

style(ggplotly(g.mean, tooltip = c("varc")), hoverinfo = "value",visible="legendonly")  #,traces = 1

Solution

  • Hide geom_ribbon() with argument "traces" in function "style()". For example : I have 10 factors in my varC so I have 10 lines (geom_line()) and 10 CI (geom_ribbon) : 20 items.

    To hide geom_ribbon() indicates to "traces" 11:20 and visible="legendonly".

    style(ggplotly(g.mean, tooltip = c("varC","x","y")),
      visible="legendonly",
      hoverinfo = "value",
      traces = c((length(unique(df$varC))+1):(length(unique(df$varC))*2)))