VennDiagram包画venn图

VennDiagram包提供了2到5个集合的绘图函数:包括绘制两个集合的韦恩图的draw.pairwise.venn,三个集合的draw.triple.venn,四个集合的draw.quad.venn, 五个集合的函数draw.quintuple.venn。
准备数据集

library(VennDiagram)rm(list=ls()) 清楚环境中的变量
A = 1:150
B = c(121:170,300:320)
C = c(20:40,141:200)
D = c(60:80,100:150)
E= c(1:60,100:120)
Length_A<-length(A)
Length_B<-length(B)
Length_C<-length(C)
Length_D<-length(D)
Length_E<-length(E)
Length_AB<-length(intersect(A,B))    #intersect() 取交集
Length_AC<-length(intersect(A,C))
Length_AD<-length(intersect(A,D))
Length_AE<-length(intersect(A,E))
Length_BC<-length(intersect(B,C))
Length_BD<-length(intersect(B,D))
Length_BE<-length(intersect(B,E))
Length_CD<-length(intersect(C,D))
Length_CE<-length(intersect(C,E))
Length_DE<-length(intersect(D,E))
Length_ABC<-length(intersect(intersect(A,B),C))
Length_ABD<-length(intersect(intersect(A,B),D))
Length_ABE<-length(intersect(intersect(A,B),E))
Length_ACD<-length(intersect(intersect(A,C),D))
Length_ACE<-length(intersect(intersect(A,C),E))
Length_ADE<-length(intersect(intersect(A,D),E))
Length_BCD<-length(intersect(intersect(B,C),D))
Length_BCE<-length(intersect(intersect(B,C),E))
Length_BDE<-length(intersect(intersect(B,D),E))
Length_CDE<-length(intersect(intersect(C,D),E))
Length_ABCD<-length(intersect(intersect(intersect(A,B),C),D))
Length_ABCE<-length(intersect(intersect(intersect(A,B),C),E))
Length_ABDE<-length(intersect(intersect(intersect(A,B),D),E))
Length_ACDE<-length(intersect(intersect(intersect(A,C),D),E))
Length_BCDE<-length(intersect(intersect(intersect(B,C),D),E))
Length_ABCDE<-length(intersect(intersect(intersect(intersect(A,B),C),D),E))

一:利用函数draw.pairwise.venn绘制两个集合的韦恩图

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)  #lty设定圆弧的线型,
col=c('red','green')   #边框颜色,
alpha = 0.7  #透明度,
fill=c('red','green')  #填充色 ,
cex = 1 #标签字体大小,
margin = 0.01 #边际距离,
cat.col=c('red','green') #表示集合名称的显示颜色,r
otation.degree=180)   #调整图形的旋转角度。
image.png

二:利用函数 draw.triple.venn绘制三个集合的韦恩图

draw.triple.venn(
area1=Length_A, area2=Length_B, area3=Length_C #area1、area2、area3分别指第一个、第二个、第三个集合的大小,
n12=Length_AB, n23=Length_BC, n13=Length_AC, n123=Length_ABC  #n12表示第一个与第二个集合的交集大小,n23、n13也是类似,n123指三个集合的交集大小,
category = c('A','B','C')   #指定集合名称,col=c('red','green','blue')  #边框颜色,
fill=c('red','green','blue')  #填充色,
cat.col=c('red','green','blue')  #表示集合名称的显示颜色,
reverse = FALSE)  #指是否对图形进行反转。
image.png

三:利用函数 draw.quad.venn绘制四个集合的韦恩图

draw.quad.venn(
area1=Length_A, area2=Length_B, area3=Length_C, area4=Length_D,
n12=Length_AB, n13=Length_AC, n23=Length_BC, n14=Length_AD, n24=Length_BD , n34=Length_CD, 
n123=Length_ABC, n124=Length_ABD, n234=Length_BCD, n134=Length_ACD, 
n1234=Length_ABCD ,category = c('A','B','C','D') ,
col=c('red','green','blue','orange'), fill=c('red','green','blue','orange') ,
alpha = 0.7 ,
lty=rep(4), cat.col=c('pink') ,
reverse = FALSE)
image.png

四:利用函数draw.quintuple.venn绘制五个集合的韦恩图

draw.quintuple.venn(
area1=Length_A, area2=Length_B, area3=Length_C, area4=Length_D, area5=Length_E,
n12=Length_AB, n13=Length_AC, n14=Length_AD, n15=Length_AE, n23=Length_BC, n24=Length_BD, n25=Length_BE, n34=Length_CD, n35=Length_CE, n45=Length_DE, 
n123=Length_ABC, n124=Length_ABD, n125=Length_ABE , n234=Length_BCD, n235=Length_BCE, n245=Length_BDE, n134=Length_ACD,n135=Length_ACE,n145=Length_ADE, n345=Length_CDE ,
n1234=Length_ABCD,n1235=Length_ABCE ,n1245=Length_ABDE, n1345=Length_ACDE, n2345=Length_BCDE,
n12345=Length_ABCDE, category = c('A','B','C','D','E') ,
col=c('red','green','blue','orange','yellow'), fill=c('red','green','blue','orange','yellow'),
alpha = 0.7,
lty=rep(4), cat.col=c('black') ,
reverse = FALSE)
image.png

你可能感兴趣的:(VennDiagram包画venn图)