提供一站式科研服务解决方案

技术服务电话
027-65528997

R|UpSetR包-集合可视化

发表时间:2022-04-02 10:16

R|UpSetR包集合的可视化

简介:对于集合的可视化,大家第一时间可能想到的都是维恩图(venn diagram),因为一般集合不超过5个的时候,可视化效果还是不错的,但是一旦数据集增加,比如说5个及以上的时候那么就很难从图中解读出想要的信息。因此,此时需要的是更高级的集合可视化,下面由小编为大家介绍R|UpSetR包-集合可视化吧。

链接: https://pan.baidu.com/s/1XIn-sX07c-LQpxLqgwGMUQ?pwd=kzd4

提取码: kzd4




绘图流程

一、安装和加载"UpSetR"包

下载"UpSetR"

install.packages("UpSetR")

加载UpSetR

library(UpSetR)

二、设置工作目录

设置工作目录

setwd("D:\\demo\\UpSerR")

三、数据整理

输出交集基因文件

outFile="intersectGenes.txt"

输出图片

outPic="upset.pdf"

获取目录下所有文件

files=dir()

提取.txt结尾的文件

files=grep("txt$",files,value=T)geneList=list() 

读取所有.txt结尾文件中的基因信息,保存到geneList

length(files)读取文件夹中所有gene长度

for(i in 1:length(files)){    inputFile=files[i]if(inputFile==outFile){next}    rt=read.table(inputFile,header=F)           读取输入文件    geneNames=as.vector(rt[,1])               提取基因名称    geneNames=gsub("^ | $","",geneNames)     去掉基因首尾的空格    uniqGene=unique(geneNames)             基因取unique,唯一基因列表    header=unlist(strsplit(inputFile,"\\.|\\-"))    geneList[[header[1]]]=uniqGene    uniqLength=length(uniqGene)    print(paste(header[1],uniqLength,sep=" "))}

四、绘图

绘制UpSet

upsetData=fromList(geneList)upset(upsetData,      nsets = length(geneList),               展示多少个数据      nintersects = 50,                       展示基因集数目      order.by = "freq",                      按照数目排序      show.numbers = "yes",                   柱状图上方是否显示数值      number.angles = 20,                     字体角度      point.size = 2,                         点的大小      matrix.color="red",                     交集点颜色      line.size = 0.8,                        线条粗细      mainbar.y.label = "Gene Intersections",      sets.x.label = "Set Size")


五、保存图片、数据

保存图片

pdf(file=outPic,onefile = FALSE,width=9,height=6)dev.off()

保存交集文件

intersectGenes=Reduce(intersect,geneList)write.table(file=outFile,intersectGenes,sep="\t",quote=F,col.names=F,row.names=F)

交集基因


关注下方公众号,获取更多精彩

作图帮
作图帮
免费分享科研作图软件及其使用方法,为科研助力!
公众号   



下一篇雷达图
分享到:
首页          产品专区          服务支持          品牌介绍          新闻活动
联系QQ:905381807
联系电话:027-65528997
联系邮箱:marketing@wefindbio.com