【问题标题】:Making plot abline lines transparent使绘图斜线透明
【发布时间】:2021-05-30 23:25:18
【问题描述】:

我想用 abline 函数绘制几条线,这些线应该是透明的,但我卡住了。

目前我有这个代码:

plot(x=NA, type="n", ylim=c(1, 9), xlim=c(1, 4), xlab="x-value",
 ylab="y-value", cex.axis = 1, cex.lab = 1)

for (i in 1:nrow(one_hundred_regressions)) {abline(coef=one_hundred_regressions[i,],
                                                col = "red")}

【问题讨论】:

    标签: r plot colors line


    【解决方案1】:

    您可以使用 RGB 颜色"#RRGGBBaa",其中aa 是透明度的 alpha 值。 例子:

    plot(1:10, type="n")
    Map(function(x, y, z) abline(coef=c(x, y), col=z, lwd=2), 2:4, 2/(2:4)^2, 
        c("#AA000066", "#00AA0066", "#0000AA66"))
    

    【讨论】:

      【解决方案2】:

      使用adjustcoloralpha 值更改为您想要的任何透明度:

      plot(1:10)
      abline(v = 1:10, col = adjustcolor("red", alpha = 0.3))
      

      【讨论】:

        猜你喜欢
        • 2014-06-06
        • 1970-01-01
        • 1970-01-01
        • 2011-03-14
        • 2010-11-25
        • 1970-01-01
        • 1970-01-01
        • 2019-03-16
        • 1970-01-01
        相关资源
        最近更新 更多