Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

rgb transparent colors in plotly and R

Tags:

r

rgb

plotly

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)

plot with purple squares

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)

plot with green fill

like image 346
user311020193 Avatar asked Dec 24 '22 09:12

user311020193


1 Answers

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)

like image 110
MLavoie Avatar answered Jan 09 '23 15:01

MLavoie