How to remove trace0 here?

社会主义新天地 提交于 2020-12-12 11:44:32

问题


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!


回答1:


Add <extra></extra>:

hovertemplate = paste('<i>Price</i>: $%{y:.2f}',
                      '<br><b>X</b>: %{x}<br>',
                      '<b>%{text}</b><extra></extra>'),


来源:https://stackoverflow.com/questions/60715706/how-to-remove-trace0-here

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!