8

The info "trace0" always shows beside the hover text box of the blue line, How can I remove it? Why not on the orange line? What the trace0 exactly mean?

library(plotly)

fig <- plot_ly() 
fig <- fig %>%
  add_trace(
    type = 'scatter',
    mode = 'lines+markers',
    x = c(1,2,3,4,5),
    y = c(2.02825,1.63728,6.83839,4.8485,4.73463),
    text = c("Text A", "Text B", "Text C", "Text D", "Text E"),
    hovertemplate = paste('<i>Price</i>: $%{y:.2f}',
                        '<br><b>X</b>: %{x}<br>',
                        '<b>%{text}</b>'),
    showlegend = FALSE
  ) 
fig <- fig %>%
  add_trace(
    type = 'scatter',
    mode = 'lines+markers',
    x = c(1,2,3,4,5),
    y = c(3.02825,2.63728,4.83839,3.8485,1.73463),
    hovertemplate = 'Price: %{y:$.2f}<extra></extra>',
    showlegend = FALSE
  )

fig

Thanks in advance!

enter image description here

Menkot
  • 694
  • 1
  • 6
  • 17

1 Answers1

12

Add <extra></extra>:

hovertemplate = paste('<i>Price</i>: $%{y:.2f}',
                      '<br><b>X</b>: %{x}<br>',
                      '<b>%{text}</b><extra></extra>'),
Stéphane Laurent
  • 75,186
  • 15
  • 119
  • 225