Customise the infoWindow / tooltip in R --> plotly

后端 未结 1 348
孤街浪徒
孤街浪徒 2020-12-17 05:23

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, s         


        
1条回答
  •  隐瞒了意图╮
    2020-12-17 06:03

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

    To edit what appears in the hover box:

    # 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 讨论(0)
提交回复
热议问题