1

I have the same question as this OP, but for R plotly instead of plot().

Is it possible to make the background of the legend of a plotly object transparent? How? If possible, partial transparency would be preferred, e.g. with an alpha level of 0.4.

1 Answers1

6

You should be able to adjust the transparency using the alpha element of rgba(0,0,0,0) for example:

library(plotly)
library(dplyr)

fig <- plot_ly(data = iris, x = ~Sepal.Length, y = ~Petal.Length, 
               color = ~Species, colors = "Set1")

# completely transparent
fig %>% layout(legend = list(x=.5, y=.5, bgcolor = 'rgba(0,0,0,0)'))

# blue background
fig %>% layout(legend = list(x=.5, y=.5, bgcolor = 'rgb(0,75,154)'))

# blue background, semi-transparent
fig %>% layout(legend = list(x=.5, y=.5, bgcolor = 'rgba(0,75,154,0.4)'))

(legends placed awkwardly on top of the plot for demonstration purposes)

KGee
  • 771
  • 7
  • 26