在plotly scatterplot中设置hoverinfo文本
我创建了一个基本的散点图,其绘图方式如下所示。问题是,虽然我特别设置了hoverinfo中的文本,但数值会在我希望显示的实际文本之前再显示一次-在plotly scatterplot中设置hoverinfo文本,r,plotly,R,Plotly,我创建了一个基本的散点图,其绘图方式如下所示。问题是,虽然我特别设置了hoverinfo中的文本,但数值会在我希望显示的实际文本之前再显示一次-(20,56)。如何删除它们 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(s
(20,56)
。如何删除它们
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
pts一种方法是通过向hovertemplate
参数中添加变量,将文本添加到每个数据点
我目前没有办法测试这个,但它应该是这样的:
add_trace(
x = ~pts,
y = ~npts,
hovertemplate = paste('<i>Team points</i>: %{x}',
'<br><b>Fantasy Pts</b>: %{y}</br>',
)
)
添加跟踪(
x=~pts,
y=~npts,
hovertemplate=paste('Team points:%{x}',
“
幻想:%{y}”,
)
)
一种方法是向每个数据点添加文本,方法是向hovertemplate
参数中添加一个变量
我目前没有办法测试这个,但它应该是这样的:
add_trace(
x = ~pts,
y = ~npts,
hovertemplate = paste('<i>Team points</i>: %{x}',
'<br><b>Fantasy Pts</b>: %{y}</br>',
)
)
添加跟踪(
x=~pts,
y=~npts,
hovertemplate=paste('Team points:%{x}',
“
幻想:%{y}”,
)
)
您刚刚拼错了参数hoverInfo
,它应该是hoverInfo
,因此您的绘图使用了默认的hoverInfo=“all”
。另外,将
替换为
,以在两行上显示悬停文本:
library(plotly)
ex您刚刚拼错了参数hoverInfo
,它应该是hoverInfo
,因此您的绘图使用了默认的hoverInfo=“all”
。另外,将
替换为
,以在两行上显示悬停文本:
library(plotly)
前任