有什么方法可以使散点图中的绘图点在 R 中更透明? [英] Any way to make plot points in scatterplot more transparent in R?

查看:41
本文介绍了有什么方法可以使散点图中的绘图点在 R 中更透明?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 3 列矩阵;图由基于第 1 列和第 2 列值的点绘制,但基于第 2 列(6 个不同组)着色.我可以成功绘制所有点,但是,最后一个被分配为紫色的绘图组(组 6)掩盖了其他组的绘图.有没有办法让情节更透明?

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

推荐答案

否则,scales 包中有函数 alpha,您可以在其中直接输入颜色向量(即使它们是您示例中的因素):

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%.

这篇关于有什么方法可以使散点图中的绘图点在 R 中更透明?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆