Using 2+ legends from R to plotly / plot.ly

前端 未结 2 1472
梦谈多话
梦谈多话 2020-12-21 15:22

I am using R\'s ggplot to create a static plot and pass that on to plot.ly to create an interactive plot. My aim to project a categorical variable to the color and a numeric

相关标签:
2条回答
  • 2020-12-21 15:54

    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)
  • 2020-12-21 16:12

    You ran into a bug, which we now fixed it.

    Please reinstall and reload the "plotly" package, re-instantiate your py object and it should work now: https://plot.ly/~marianne2/38/or-illn-vs-or-edu/

    0 讨论(0)
提交回复
热议问题