【发布时间】:2019-03-06 07:33:23
【问题描述】:
我想将文本添加到 plotly。例如,代码无法将 mytext 添加到 ply.test 图中?任何人都可以提供帮助。谢谢!
test.dat <- data.frame(xmin=c(0,1.5), ymin=c(-1,-1), xmax=c(1,2), ymax=c(1,1), col=c("blue", "red"))
ggp.test <- ggplot() + geom_rect(data=test.dat, aes(xmin=xmin, ymin=ymin, xmax=xmax, ymax=ymax, group = col), fill=test.dat$col) + theme_bw()
ggp.test
# How to add the text as hoverinfo?
ply.test <- plotly_build(ggp.test)
ply.test
mytext <- paste(test.dat$xmin,test.dat$ymin,sep = "")
style(ply.test, text = mytext, hoverinfo = "text", traces = c(0,1 ))
【问题讨论】:
-
尝试把最后一行代码改成
traces = c(1,2) -
只需更改痕迹。它没有用。
-
您想将 mytext 中的文本添加到绘图中,还是希望在您将鼠标悬停在栏上时显示此文本?
-
是的,我希望我的文字在鼠标悬停在栏上时出现