这是我在教程中使用的代码https://blog.cpsievert.me/2018/03/30/visualizing-geo-spatial-data-with-sf-and-plotly/:
library(plotly)
data(franconia, package = "mapview")
plot_ly(
franconia,
split = ~NUTS_ID,
color = ~district,
stroke = I("black"),
text = ~paste("This is text and",NAME_ASCI, "\n is in", district),
hoverinfo = "text",
hoveron = "fill"
)
我希望悬停工具提示中的文本是
text
属性。但是,当我运行此命令时,悬停工具提示中的文本是 split
属性。
我相信
hoveron
值应该是 "fills"
:
library(plotly)
data(franconia, package = "mapview")
plot_ly(
franconia,
split = ~NUTS_ID,
color = ~district,
stroke = I("black"),
text = ~paste("This is text and",NAME_ASCI, "\n is in", district),
hoverinfo = "text",
hoveron = "fills"
)
#> No trace type specified:
#> Based on info supplied, a 'scatter' trace seems appropriate.
#> Read more about this trace type -> https://plotly.com/r/reference/#scatter
有很多
hoveron = "fill"
参考资料,我想这在某些时候已经发生了变化,尽管也有最新的例子,例如https://plotly-r.com/maps#cb63-1 .
在这种特殊情况下,
No trace type specified
通知和参考链接非常方便。好吧,单页引用可能会导致搜索混乱,所以这个变体更好一些 - https://plotly.com/r/reference/scatter/#scatter-hoveron。它列出了 "points"
、"fills"
、"points+fills"
作为可用选项。
我不记得这样的语法细节,但不久前我有自己的 Plotlyl 挣扎着,从那次会议中回忆起一些关于 "/../ fill 和 fills 行为不同 /../" 的事情。就是这个问题 - https://github.com/plotly/plotly.R/issues/1260.