2009-09-15 483 views
24

除了limma軟件包外,還有其他用於R中Venn圖表的軟件包。維恩圖與R?

任何人都有提示?

這裏有一些notes on doing Venn diagrams與limma包。

+3

嗨,我仍然在尋找一個能夠繪製比例維恩圖的軟件包。這是我從8年前發現的最接近的東西,https://stat.ethz.ch/pipermail/r-help/2003-February/029393.html。我希望這會有一個更新的發展。 – andrewj 2011-03-03 21:58:18

+1

http://www.caleydo.org/tools/upset/ – wikiselev 2016-12-05 14:33:30

回答

5

如果您需要創建4/5組的維恩圖,gplots包中的維恩函數也很有用。

7

我使用兩個自定義函數。我對venndia的實現繪製了維恩圖,並返回A和B(和C)之間的重疊列表。請參閱下面的代碼。

有了這些,你可以

vd <- venndia(A=LETTERS[1:15], B=LETTERS[5:20], getdata=TRUE) 

這都將劇情和返回數據。您可以關閉返回數據

venndia(A=LETTERS[1:15], B=LETTERS[5:20]) 

因爲getdata默認爲FALSE。 /丹尼爾

circle <- function(x, y, r, ...) { 
    ang <- seq(0, 2*pi, length = 100) 
    xx <- x + r * cos(ang) 
    yy <- y + r * sin(ang) 
    polygon(xx, yy, ...) 
} 

venndia <- function(A, B, C, getdata=FALSE, ...){ 
    cMissing <- missing(C) 
    if(cMissing){ C <- c() } 

    unionAB <- union(A, B) 
    unionAC <- union(A, C) 
    unionBC <- union(B, C) 
    uniqueA <- setdiff(A, unionBC) 
    uniqueB <- setdiff(B, unionAC) 
    uniqueC <- setdiff(C, unionAB) 
    intersAB <- setdiff(intersect(A, B), C) 
    intersAC <- setdiff(intersect(A, C), B) 
    intersBC <- setdiff(intersect(B, C), A) 
    intersABC <- intersect(intersect(A, B), intersect(B, C)) 

    nA <- length(uniqueA) 
    nB <- length(uniqueB) 
    nC <- length(uniqueC) 

    nAB <- length(intersAB) 
    nAC <- length(intersAC) 
    nBC <- length(intersBC) 

    nABC <- length(intersABC) 

    par(mar=c(2, 2, 0, 0)) 
    plot(-10, -10, ylim=c(0, 9), xlim=c(0, 9), axes=FALSE, ...) 
    circle(x=3, y=6, r=3, col=rgb(1,0,0,.5), border=NA) 
    circle(x=6, y=6, r=3, col=rgb(0,.5,.1,.5), border=NA) 
    circle(x=4.5, y=3, r=3, col=rgb(0,0,1,.5), border=NA) 

    text(x=c(1.2, 7.7, 4.5), y=c(7.8, 7.8, 0.8), c("A", "B", "C"), cex=3, col="gray90") 

    text(
     x=c(2, 7, 4.5, 4.5, 3, 6, 4.5), 
     y=c(7, 7, 2 , 7 , 4, 4, 5), 
     c(nA, nB, nC, nAB, nAC, nBC, nABC), 
     cex=2 
    ) 

    if(getdata){ 
     list(A=uniqueA, B=uniqueB, C=uniqueC, 
      AB=intersAB , AC=intersAC , BC=intersBC , 
      ABC=intersABC 
     ) 
    } 
} 
9

Vennerable package on R-forge

source("http://bioconductor.org/biocLite.R") 
biocLite(c("graph", "RBGL", "gtools", "xtable")) 
install.packages("Vennerable", repos="http://R-Forge.R-project.org") 

Venn diagram

6

這都很晚,但它可能爲他人尋找答案有用: VennDiagram,在CRAN here

它允許多套(venn四套,Euler圖三套),可自定義的顏色和字體,簡單的語法,並且所有圓的最大尺寸與數據集的大小成正比(至少當比較2個數據集時)。要安裝:

install.packages("VennDiagram") 
library(VennDiagram) 

對於使用Bioconductor的包,並與基因組座標的工作,最近文氏圖是在包ChIPpeakAnno(2.5.12版本)implemented並允許基因組座標的交叉漂亮,例如,芯片起峯。對於早期使用者,您可能需要安裝development package

peaks1 = RangedData(IRanges(start = c(967654, 2010897, 2496704), 
    end = c(967754, 2010997, 2496804), names = c("Site1", "Site2", "Site3")), 
    space = c("1", "2", "3"), strand=as.integer(1),feature=c("a","b","f")) 

peaks2 = RangedData(IRanges(start = c(967659, 2010898,2496700,3075866,3123260), 
    end = c(967869, 2011108, 2496920, 3076166, 3123470), 
    names = c("t1", "t2", "t3", "t4", "t5")), 
    space = c("1", "2", "3", "1", "2"), strand = c(1, 1, -1,-1,1), feature=c("a","b","c","d","a")) 

makeVennDiagram(RangedDataList(peaks1,peaks2, peaks1, peaks2), NameOfPeaks=c("TF1", "TF2","TF3", "TF4"), 
    totalTest=100,useFeature=TRUE, main="Venn Diagram", 
    col = "transparent",fill = c("cornflowerblue", "green", "yellow", "darkorchid1"), 
    alpha = 0.50,label.col = c("orange", "white", "darkorchid4", "white", "white", "white", "white", "white", "darkblue", "white", "white", "white", "white", "darkgreen", "white"), cat.col = c("darkblue", "darkgreen", "orange", "darkorchid4")) 
+0

vennDiagram最多允許5組 – OganM 2015-02-04 22:33:07

+0

我去了論文,它是'最多四組和歐拉圖,最多三組。' – fridaymeetssunday 2015-02-06 06:48:15

+1

從版本1.6.16開始,'VennDiagram'有一個函數'draw.quintuple.venn()',它爲五組繪製一個維恩圖。 – 2015-10-01 11:23:16

0

這裏是參照其他的版本爲3位可變數據: http://elliotnoma.wordpress.com/2011/02/09/venn-diagram/

該代碼也可在包colorfulVennPlot: http://cran.r-project.org/web/packages/colorfulVennPlot/index.html

+2

請注意,您應該在此處發佈答案的有用觀點,或將您的帖子風險刪除爲[「未答覆」](http://meta.stackexchange.com/q/8259)。如果您願意,您可能仍然包含鏈接,但僅作爲「參考」。答案應該獨立,不需要鏈接。 – 2013-01-31 19:32:15