温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

如何使用R语言来绘制韦恩图

发布时间:2021-07-20 18:14:37 来源:亿速云 阅读:1442 作者:chen 栏目:大数据

这篇文章主要介绍“如何使用R语言来绘制韦恩图”,在日常操作中,相信很多人在如何使用R语言来绘制韦恩图问题上存在疑惑,小编查阅了各式资料,整理出简单好用的操作方法,希望对大家解答”如何使用R语言来绘制韦恩图”的疑惑有所帮助!接下来,请跟着小编一起来学习吧!

> install.packages("VennDiagram")

> library(VennDiagram)

> A = 1:150

> B = c(121:170,300:320)

> C = c(20:40,141:200)

> Length_A<-length(A)

> Length_B<-length(B)

> Length_C<-length(C)

> Length_AB<-length(intersect(A,B))

> Length_BC<-length(intersect(B,C))

> Length_AC<-length(intersect(A,C))

> Length_ABC<-length(intersect(intersect(A,B),C))

> T<-venn.diagram(list(A=A,B=B),filename=NULL,lwd=1,lty=2, ,col=c('red','green'),fill=c('red','green'),cat.col=c('red','green'),rotation.degree=90)

> grid.draw(T)

如何使用R语言来绘制韦恩图

> T<-venn.diagram(list(A=A,B=B,C=C),filename=NULL,lwd=1,lty=2,col=c('red','green','blue') ,fill=c('red','green','blue'),cat.col=c('red','green','blue'),reverse=TRUE)

> grid.draw(T)

如何使用R语言来绘制韦恩图

>draw.pairwise.venn(area1=Length_A,area2=Length_B,cross.area=Length_AB,category=c('A','B'),lwd=rep(1,1),lty=rep(2,2),col=c('red','green'),fill=c('red','green'),cat.col=c('red','green'),rotation.degree=90)

如何使用R语言来绘制韦恩图

这种方式画的图与第一种方式画出结果一样!接下来利用draw.triple.venn绘制三个集合的韦恩图

> draw.triple.venn(area1=Length_A, area2=Length_B, area3=Length_C,n12=Length_AB, n23=Length_BC, n13=Length_AC, n123=Length_ABC,category = c('A','B','C'),col=c('red','green','blue'),fill=c('red','green','blue'),cat.col=c('red','green','blue')

,reverse = FALSE)

如何使用R语言来绘制韦恩图

傻瓜式代码如下:

> install.packages("VennDiagram")

> library(VennDiagram)

> A <- c("C", "D", "B", "E") #生成三个不同的集合

> B <- c("C", "E", "B", "A")

> C <- c("C", "E", "X", "Y")

> venn.diagram(x=list(Tumor=A, Organoids=B, Primary=C), "My1.png", height = 450, width = 450, resolution =300, imagetype="png", col="white", fill=c(colors()[616], colors()[38], colors()[468]), alpha=c(0.6, 0.6, 0.6), lwd=c(1, 1, 1), cex=0, cat.dist=c(-0.07, -0.07, -0.05), cat.pos=c(300, 60, 180), cat.cex=0.45) #height、width、resolution等的含义参考help()函数即可了解,这里备注下“My 1.png“是图片保存文件名称,倘若不想以文件的形式保存,则filename必须为空,即filename=NULL。

如何使用R语言来绘制韦恩图

> D <- c("C", "D", "B", "E") #生成三个不同的组合

> E <- c("C", "F", "G", "K")

> F <- c("C", "H", "X", "Y")

>venn.diagram(x=list(Tumor=D, Organoids=F,Primary=E), "My2.png", height = 450, width = 450, resolution =300, imagetype="png", col="gray",fill=c(colors()[148], colors()[589], colors()[116]), alpha=c(0.6, 0.6, 0.6), lwd=0.5, cex=0, cat.dist=c(-0.07, -0.07, -0.05), cat.pos=c(100, 260, 0),cat.cex=0.45, cat.col="black", rotation.degree=180)

如何使用R语言来绘制韦恩图

> A<- sample(1:1000, 400, replace = FALSE) #生成四个不同的组合

> B<- sample(1:1000, 600, replace = FALSE)

> C<- sample(1:1000, 350, replace = FALSE)

> D<- sample(1:1000, 550, replace = FALSE)

> venn.diagram(x= list(A = A,D = D,B = B,C = C), filename = "My3.png", height = 450, width = 450,resolution =300, imagetype="png", col ="transparent", fill =c("cornflowerblue","green","yellow","darkorchid1"),alpha = 0.5, label.col = c("orange", "white","darkorchid4", "white", "white", "white",    "white", "white","darkblue", "white", "white", "white","white", "darkgreen", "white"), cex = 0.45,fontfamily = "serif", fontface = "bold",cat.col =c("darkblue", "darkgreen", "orange","darkorchid4"), cat.cex = 0.45,cat.pos = 0, cat.dist = 0.07,cat.fontfamily = "serif", rotation.degree = 270)

如何使用R语言来绘制韦恩图

> A<- sample(LETTERS, 18, replace = FALSE)

> B<- sample(LETTERS, 20, replace = FALSE)

> C<- sample(LETTERS, 22, replace = FALSE)

> D<- sample(LETTERS, 19, replace = FALSE)

> venn.diagram(x= list(A = A,D = D,B = B,C = C), filename = "My4.png", height = 450, width = 450,resolution =300, imagetype="png", col="transparent",fill=c("cornflowerblue","green","yellow","darkorchid1"),alpha = 0.50, cex=0.45, cat.cex=0.45)

如何使用R语言来绘制韦恩图

> venn.diagram(x =list(A = A,D = D,B = B,C = C), filename = "My5.png", height = 450, width= 450, resolution =300, imagetype="png", lwd=0.6, fill =c("cornflowerblue","green","yellow","darkorchid1"),cex=0.45, cat.cex=0.45)

如何使用R语言来绘制韦恩图

当然韦恩图会画,最重要的还是要会分析!

到此,关于“如何使用R语言来绘制韦恩图”的学习就结束了,希望能够解决大家的疑惑。理论与实践的搭配能更好的帮助大家学习,快去试试吧!若想继续学习更多相关知识,请继续关注亿速云网站,小编会继续努力为大家带来更多实用的文章!

向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI