简体   繁体   English

r-plotly 图例背景(部分)透明

[英]r-plotly legend background (partly) transparent

I have the same question as this OP , but for R plotly instead of plot().我和这个 OP有同样的问题,但是对于 R plotly 而不是 plot()。

Is it possible to make the background of the legend of a plotly object transparent?是否可以使plotly object的图例背景透明? How?如何? If possible, partial transparency would be preferred, eg with an alpha level of 0.4.如果可能,部分透明度将是首选,例如 alpha 级别为 0.4。

You should be able to adjust the transparency using the alpha element of rgba(0,0,0,0) for example:您应该能够使用 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)'))

(legends placed awkwardly on top of the plot for demonstration purposes) (出于演示目的,图例笨拙地放在 plot 顶部)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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