I have a 3 column matrix; plots are made by points based on column 1 and column 2 values, but colored based on column 2 (6 different groups). I can successfully plot all points, however, the last plot group (group 6) which was assigned the color purple, masks the plots of the other groups. Is there a way to make the plot points more transparent?
s <- read.table("/.../parse-output.txt", sep="\t") dim(s) [1] 67124 3 x <- s[,1] y <- s[,2] z <- s[,3] cols <- cut(z, 6, labels = c("pink", "red", "yellow", "blue", "green", "purple")) plot(x, y, main= "Fragment recruitment plot - FR-HIT", ylab = "Percent identity", xlab = "Base pair position", col = as.character(cols), pch=16)
Utilize the alpha argument in our scatter method and pass in a numeric value between 0 and 1. A value of 0 will make the plots fully transparent and unable to view on a white background.
The only way to specify alpha values at present are via the special colour name "transpar- ent", which produces a fully transparent white, or using the alpha graphical parameter in grid (see the examples below). The alpha graphical parameter is a number from 0 to 1 (opaque to transparent).
Change R base plot point shapes To change the color and the size of points, use the following arguments: col : color (hexadecimal color code or color name). For example, col = "blue" or col = "#4F6228" .
Otherwise, you have function alpha
in package scales
in which you can directly input your vector of colors (even if they are factors as in your example):
library(scales) cols <- cut(z, 6, labels = c("pink", "red", "yellow", "blue", "green", "purple")) plot(x, y, main= "Fragment recruitment plot - FR-HIT", ylab = "Percent identity", xlab = "Base pair position", col = alpha(cols, 0.4), pch=16) # For an alpha of 0.4, i. e. an opacity of 40%.
When creating the colors, you may use rgb
and set its alpha
argument:
plot(1:10, col = rgb(red = 1, green = 0, blue = 0, alpha = 0.5), pch = 16, cex = 4) points((1:10) + 0.4, col = rgb(red = 0, green = 0, blue = 1, alpha = 0.5), pch = 16, cex = 4)
Please see ?rgb
for details.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With