您好,登錄后才能下訂單哦!
這篇文章主要介紹“如何使用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)
> 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)
>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)
這種方式畫的圖與第一種方式畫出結果一樣!接下來利用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)
傻瓜式代碼如下:
> 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。
> 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)
> 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)
> 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)
> 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語言來繪制韋恩圖”的學習就結束了,希望能夠解決大家的疑惑。理論與實踐的搭配能更好的幫助大家學習,快去試試吧!若想繼續學習更多相關知識,請繼續關注億速云網站,小編會繼續努力為大家帶來更多實用的文章!
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。