简体   繁体   中英

rgb transparent colors in plotly and R

I am trying to get a plotly graph with a filled area that is semi-transparent purple. I can find the rgb designation fine and get it to work in a simple plot. But it seems that plotly doesn't read in rgb's the usual way?

plot(rnorm(10),col="#A020F066",pch=15,cex=13)
# plots squares that are transparent purple (expected)

情节与紫色方块

p=plot_ly(x=c(1,2,3,4),y=c(1,2,5,10),type="scatter",line=list(color="red"))
p=add_trace(p,x=c(1,2,3,4),y=c(11,12,15,20),type="scatter",
        fillcolor="#A020F066",fill="tonexty",
        line=list(width=10),marker=list(size=10))
p
# plots area that is transparent mint green (What? I expected purple)

情节与绿色填充

According to the plotly website, the full list of rgb / hex available is found here ( http://reeddesign.co.uk/test/namedcolors.html ). So for your example, you would need to use fillcolor="#8a2be2" . Alternatively, you can also use something like this fillcolor="rgba(147,112,219,0.1) with the last digit being the alpha (opacity)

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