在plotly散点图中设置hoverinfo文本 [英] Set hoverinfo text in plotly scatterplot
本文介绍了在plotly散点图中设置hoverinfo文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我用下面的图创建了一个基本的散点图.问题是,虽然我专门在hoverinfo中设置了文本,但数值却要多显示一次-(20,56)
-在要显示的实际文本-Team Pts:20 Fantasy Pts: 56
之前.如何删除它们?
I create a basic scatterplot with plotly like the one below. The issue is that while I set specifically the text inside the hoverinfo the numeric values are displayed one more time- (20,56)
-before the actual text- Team Pts:20 Fantasy Pts: 56
-that I wish to display. How can I delete them?
pts<-c(10,20,30)
npts<-c(24,56,78)
ex<-data.frame(pts,npts)
library(plotly)
p <- plot_ly(data = ex, x = ~pts, y = ~npts,
marker = list(size = 10,
color = 'white',
line = list(color = 'rgba(152, 0, 0, .8)',
width = 2))) %>%
add_trace(
text = ~paste("Team Pts: ", pts, '</br>Fantasy Pts:', npts),
hoverInfo='text'
)
p
推荐答案
一种方法是通过在hovertemplate
参数中添加变量,将文本添加到每个数据点.
One way of doing this is to add the text to each data point, by adding in a variable to the hovertemplate
parameter.
我目前无法测试此方法,但它看起来应该像这样:
I don't have a way to test this at the moment, but it should look something like this:
add_trace(
x = ~pts,
y = ~npts,
hovertemplate = paste('<i>Team points</i>: %{x}',
'<br><b>Fantasy Pts</b>: %{y}</br>',
)
)
这篇关于在plotly散点图中设置hoverinfo文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文