我创建了一个基本的散点图,并添加了一条平均线。是否可以添加"Average : <Average Value>"
之类的hoverinfo文本?另一个解决方案是将文本永久显示在行上,但我认为这可能更复杂。
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_segments(x = 0, xend = max(ex$pts), y = mean(ex$npts), yend =mean(ex$pts) )%>%
add_trace(
text = ~paste("Team Pts: ", pts, '</br>Fantasy Pts:', npts),
hoverInfo='text'
)
p