Making plot abline lines transparent

Viewed 519

I would like to use the function abline to plot several lines which should be made transparent but I am stuck.

Currently I have this code:

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")}
2 Answers

Use adjustcolor changing the alpha value to whatever degree of transparency you want:

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

screenshot

You may use RGB colors "#RRGGBBaa", where aa is the alpha value for transparency. Example:

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"))

enter image description here

Related