您应该能够使用 rgba(0,0,0,0) 的 alpha 元素调整透明度,例如:
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)'))
Run Code Online (Sandbox Code Playgroud)
(出于演示目的,图例尴尬地放置在情节顶部)