How to get Plotly.js default colors list?

后端 未结 5 1766
陌清茗
陌清茗 2020-12-08 20:48

I am plotting a plotly bubble chart on a webpage.. I want to get the list of default colors, plotly uses to draw the bubbles.

5条回答
  •  悲&欢浪女
    2020-12-08 21:16

    You can also use something like this to retrieve the colours used in your plot:

    return.plot_ly.ColorsUsed <- function( plotlyObject ) {
    
          explorePlot = plotly_json(plotlyObject)
          explorePlot = jsonlite::fromJSON(explorePlot$x$data)
    
          # Extract colors, names and fillcolors
          colors = explorePlot$data$marker$color
          names = explorePlot$data$name
          fillcolors = explorePlot$data$marker$fillcolor
    
    
    
          # Returns a list with the names, colors and fillcolors used in the plot
          toReturn = list( "names" = names,
                           "colors" = colors,
                           "fillcolors" = fillcolors )
    
          return(toReturn)
    
    
    } # End FUnction return.plot_ly.ColorsUsed
    

提交回复
热议问题