【问题标题】:rgb transparent colors in plotly and Rplotly和R中的rgb透明颜色
【发布时间】:2016-02-04 23:35:52
【问题描述】:

我正在尝试获得一个带有半透明紫色填充区域的绘图图。我可以很好地找到 rgb 名称并让它在一个简单的情节中工作。但似乎 plotly 不是以通常的方式读取 rgb 的?

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)

【问题讨论】:

    标签: r rgb plotly


    【解决方案1】:

    根据 plotly 网站,可在此处找到完整的 rgb / hex 列表 (http://reeddesign.co.uk/test/namedcolors.html)。因此,对于您的示例,您需要使用fillcolor="#8a2be2"。或者,您也可以使用类似 fillcolor="rgba(147,112,219,0.1) 的东西,最后一位数字是 alpha(不透明度)

    【讨论】:

    • 我自己想出来的。 R 读取“#A020F066”作为颜色 A020F0 和透明度(十六进制)66。所以最后 2 位数字控制不透明度。 Plotly 将 A0 读取为透明度部分,将最后 6 位数字读取为颜色。不透明度在一般 R 中最后,不透明度在情节中首先。使用这个技巧,我可以让我的情节重现薄荷绿或情节成为我想要的透明紫色。
    • 我试过添加两位数,但它不起作用。任何人都可以解决这个问题?
    猜你喜欢
    • 1970-01-01
    • 2021-07-26
    • 1970-01-01
    • 2018-11-15
    • 1970-01-01
    • 2012-05-10
    • 2020-04-08
    • 1970-01-01
    相关资源
    最近更新 更多