2014-10-02 49 views
2

我是plot.ly的新手,我剛剛從R中抽出了我的第一個散點圖 - 非常棒!在R中自定義infoWindow/tooltip - > plotly

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等等。

謝謝!

回答

0

問題和答案原本張貼在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))