如何在R的Plotly绘图中移除hovertemplate旁的trace0标识
解决Plotly绘图中hovertemplate旁显示"trace0"的问题
你只需要在自定义的hovertemplate末尾加上<extra></extra>标签,就能去掉这个默认显示的trace名称。
原因是Plotly默认会在hover提示框的额外区域显示当前trace的名称(因为你没给trace指定name参数,所以默认显示"trace0"),<extra></extra>可以替换这个默认区域的内容,留空就不会显示任何额外信息了。
修改后的完整代码如下:
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>', '<extra></extra>'), showlegend = FALSE )
内容的提问来源于stack exchange,提问作者firmo23
相关产品推荐
相关产品推荐

