Home > OS >  Set dynamic hoverlabel background color in R plotly scattergl
Set dynamic hoverlabel background color in R plotly scattergl

Time:04-03

The dynamic hoverlabel background color in R plotly does not seem to work when using scattergl instead of scatter as depicted in the example below.

Works as intended with type = "scatter":

library(plotly)

X <- data.frame(x = 1:6,
                y = 1:6,
                z  = 1:6)

plot_ly(data = X, x = ~x, y = ~y,
        type = "scatter", mode = "markers",
        marker = list(color = ~x, 
                      colorscale = list(c(0, .5, 1), c('#0d71db', "#dbc00d", "#db220d"))))

enter image description here

The hoverlabel background color becomes black for all data points with type = "scattergl":

plot_ly(data = X, x = ~x, y = ~y,
        type = "scattergl", mode = "markers",
        marker = list(color = ~x, 
                      colorscale = list(c(0, .5, 1), c('#0d71db', "#dbc00d", "#db220d"))))

enter image description here

I guess a solution could be to pass the same color array used in colorscale to the enter image description here

As you can see from the plot, the label is the same color as the marker.

  • Related