Making Plot Abline Lines Transparent

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

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Chloe Bennett

Chloe Bennett

Culture, Media & Entertainment Columnist

Chloe Bennett explores the intersection of pop culture, streaming entertainment, digital trends, and contemporary lifestyle. Her weekly commentary reaches thousands of culture enthusiasts.

Share this article
Twitter Facebook Pinterest