简体   繁体   中英

r-plotly legend background (partly) transparent

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, eg with an alpha level of 0.4.

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)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM