【问题标题】:Customise the infoWindow / tooltip in R --> plotly自定义 R 中的 infoWindow / tooltip --> plotly
【发布时间】:2014-11-26 23:19:33
【问题描述】:

我是 plot.ly 的新手,前几天我刚刚从 R 中绘制了我的第一个散点图 - 太棒了!

testplot <- ggplot(a, aes(OR_Edu, OR_Illn, color=Country, size=total)) + geom_point()
py$ggplotly(testplot)

https://plot.ly/~SyTpp/14/or-illn-vs-or-edu/

现在,我想更改工具提示或将鼠标悬停在数据点上时弹出的小信息窗口。在这种情况下,我对 y 坐标不感兴趣,但我想显示国家名称和人口规模,我将其映射到 aestectic 规模。

理想情况下,我想知道我是否/如何可以自定义信息窗口,甚至可能在我的数据框中显示每个国家/地区的变量,我没有在 aes() 中给出图,例如一个国家的GDP等等等等。

谢谢!

【问题讨论】:

  • 你试过ggiraph包吗?

标签: r ggplot2 plotly


【解决方案1】:

问题和答案最初发布在Using 2+ legends from R to plotly / plot.ly

编辑悬停框中显示的内容:

# Load "plotly"
library(plotly)
# Open a Plotly connection
py <- plotly()

# Retrieve a Plotly graph in R
hover_text <- py$get_figure("PlotBot", 81)

str(hover_text$data)
# This list has 4 elements, which all have dimension (attribute) 'text'

# You can overwrite them one by one, say
hover_text$data[[1]]$text[1]
hover_text$data[[1]]$text[1] <- "US"

# If you need something functional, I would recommend defining the necessary
# functions and using sapply()

# Plotly graph with hover text we just edited
py$plotly(hover_text$data, kwargs=list(layout=hover_text$layout))

【讨论】:

    猜你喜欢
    • 2016-06-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-07-06
    • 2018-03-17
    • 2019-04-23
    • 1970-01-01
    相关资源
    最近更新 更多