Set up info tool / tooltip in R & # 8594; plotly

I'm new to plot.ly and the other day I just drew my first scatter from R - that's 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 small info window that appears when you hover over a datapoint. In this case, I am not interested in the y coordinate, but instead I would like to display the name of the country and the size of the population, which I compared with the aesthetic size.

Ideally, I would like to know if / how I can configure infowindow at all, maybe even display the variables in my dataframe for each country, which I do not give the plot in aes (), for example. Country's GDP, etc. etc.

Thanks!

+2
source share
1 answer

Question and answer were originally sent to Using 2+ legends from R to plotly / plot.ly

To edit what appears in the guidance field:

 # 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)) 
0
source

All Articles