The standard colors in R are opaque, but you can add an alpha value to make them semi-transparent. In this example we set alpha halfway between 0 and 255 to define a semi-transparent red:
> set.seed(42) > x <- runif(10)*10 > y <- runif(10)*10 > plot(x, y, pch=16) > col2rgb("red", alpha=TRUE) [,1] red 255 green 0 blue 0 alpha 255 > redtrans <- rgb(255, 0, 0, 127, maxColorValue=255) > polygon(c(2, 5, 8), c(2, 10, 2), col=redtrans) ------------------------------------- David L Carlson Department of Anthropology Texas A&M University College Station, TX 77840-4352 -----Original Message----- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of Jun Shen Sent: Wednesday, May 21, 2014 10:32 AM To: R-help Subject: [R] How to draw a transparent polygon Hi everyone, How do I draw a transparent ploygon overlaying with a scatter plot? Let's say, we call plot() to have a scatter plot, then call polygon() to add a polygon. I was hoping the polygon can be transparent so the scatter plot is still visible. I can't find any argument in polygon() for such a feature. Is there another way to do it? Thanks. Jun Shen [[alternative HTML version deleted]] ______________________________________________ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. ______________________________________________ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.