本文介绍了在R中自定义infoWindow / tooltip - > plotly的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞! 我是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坐标不感兴趣,但我希望显示国家名称和人口规模,我将其映射到无意义的大小。 理想情况下,我想知道我是否可以自定义infowindow,甚至可以在我的数据框中显示每个国家/地区的变量在aes()中,例如一个国家的GDP等等。 谢谢! 解决方案问题和答案最初发布在使用来自R的2+传说to plotly / plot.ly 要编辑悬停框中显示的内容: $打开一个Plotly连接 py< - plotly() #在R hover_text中检索Plotly图形< - py $ get_figure(PlotBot,81) str(hover_text $ data)#此列表包含4个元素,所有都有维(属性)'文本' #你可以一个接一个地覆盖它们,比如 hover_text $ data [[1]] $ text [1] hover_text $ data [[1]] $ text [1]< - US #如果你需要一些功能,我建议定义必要的#函数并使用sapply() #我们刚刚编辑了 py的悬停文字图$ plotly(hover_text $ data,kwargs = list(layout = hover_text $ layout)) I am new to plot.ly and I just drew my first scatter plot out of R the other day - its great! 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/Now, I would like to change the tooltip or the little info window that pops up on hover over a datapoint. In this case I am not interested in the y-coordinate but instead I would like to display the country name and the population size, which I mapped to the aestectic size.Ideally I would like to know if/how I can customize the infowindow in general, maybe even display variables in my dataframe for each country which I don't give the plot in aes(), e.g. the GDP of a country etc etc..Thanks! 解决方案 Question and answer were originally posted at Using 2+ legends from R to plotly / plot.lyTo edit what appears in the hover box:# Load "plotly"library(plotly)# Open a Plotly connectionpy <- plotly()# Retrieve a Plotly graph in Rhover_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, sayhover_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 editedpy$plotly(hover_text$data, kwargs=list(layout=hover_text$layout)) 这篇关于在R中自定义infoWindow / tooltip - > plotly的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云! 08-04 20:48