简体   繁体   English

如何更改 R 中绘图多边形或色带的不透明度?

[英]How to change the opacity of a plotly polygon or ribbon in R?

In plotly for R there is an opacity argument for lines and markers, but how do I change the opacity of fill colours in add_ribbons and add_polygons ?在 R 的情节中,线条和标记有一个不透明度参数,但是如何更改add_ribbonsadd_polygons中填充颜色的不透明度?

eg opacity = 0 makes the line disappear here:例如opacity = 0使线条在这里消失:

plot_ly() %>% add_lines(x = 1:4, y = 1:4, color = I("red"), opacity = 0)

but has no effect on the polygon here:但对这里的多边形没有影响:

plot_ly() %>% add_polygons(x = c(1, 1, 2, 2), y = c(1, 2, 2, 1), 
                           color = I("red"), opacity = 0)

Using alpha doesn't work either.使用alpha也不起作用。 How can I change the opacity of fill colors?如何更改填充颜色的不透明度?

As an alternative you could try using fillColor and rgba color (last digit being alpha):作为替代方案,您可以尝试使用fillColorrgba颜色(最后一位数字是 alpha):

%>% add_polygons(fillcolor = 'rgba(7, 164, 181, 1)')

vs对比

%>% add_polygons(fillcolor = 'rgba(7, 164, 181, 0.2)')

Just adjust the numbers for the colour you want.只需调整您想要的颜色的数字。

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

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