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?

e.g. ‘opacity=0’ makes the line disappear here:

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. How can I change the opacity of fill colors?

Hey @jimt,

it seems to work for me with 4.5.6.900

a <- plot_ly()%>%add_polygons(x=c(1,1,2,2),y=c(1,2,2,1),color=I("red"),opacity = 0.1)
aa <- plot_ly()%>%add_polygons(x=c(1,1,2,2),y=c(1,2,2,1),color=I("red"),opacity = 0.8)
subplot(a,aa)

Alternatively, you can use shapes in the layout https://plot.ly/r/shapes/#rectangles.

Thanks bcd,
I’ve updated the package but still no luck with I(), but toRGB() does the trick…

http://stackoverflow.com/questions/41648523/how-to-change-the-opacity-of-a-plotly-polygon-or-ribbon-in-r