Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to remove trace0 here?

Tags:

r

plotly

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

like image 706
Jane Avatar asked Apr 22 '26 08:04

Jane


1 Answers

Add <extra></extra>:

hovertemplate = paste('<i>Price</i>: $%{y:.2f}',
                      '<br><b>X</b>: %{x}<br>',
                      '<b>%{text}</b><extra></extra>'),
like image 77
Stéphane Laurent Avatar answered Apr 24 '26 23:04

Stéphane Laurent