任何方式使散点图中的绘图点在R中更透明? [英] Any way to make plot points in scatterplot more transparent in R?

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

问题描述

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

  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 ,绿色,紫色))
plot(x,y,main =片段招募绘图-FR-HIT,ylab =百分比同一性,xlab =基础对位置 as.character(cols),pch = 16)


解决方案

否则,您可以在包中个比例中使用 alpha 函数,您可以直接输入颜色矢量(即使它们是因为在你的例子中):

  library(比例)
cols< - cut(z,6,labels = c(粉红色,红色,黄色,蓝色,绿色,紫色))
plot(x,y,main =片段招募绘图 - FR-HIT,
ylab =百分比标识,xlab =基准对位置,
col = alpha(cols,0.5),pch = 16)
#对于α的0.5,i。即50%的透明度。


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) 

解决方案

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.5), pch=16) 
# For an alpha of 0.5, i. e. a transparency of 50%.

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

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