如何使用R绘制维恩图

Jac*_*ack 3 r venn-diagram

我有三个ID列表.

我想比较3个列表,并绘制一个维恩图.在获得的维恩图中,我将在交叉点显示不是数字而是ID.我需要在R中这样做,但我真的不知道如何.你可以帮帮我吗?那是我的代码.它有效,但只显示数字,我会在交叉点显示"条款"

       set1 <- unique(goterm1)
       set2 <- unique(goterm2)
        set3 <- unique(goterm3)

       require(limma)
       Diagram <- function(set1, set2, set3, names)
       {
     stopifnot( length(names) == 3)
      # Form universe as union of all three sets
      universe <- sort( unique( c(set1, set2, set3) ) )
      Counts <- matrix(0, nrow=length(universe), ncol=3)
      colnames(Counts) <- names
        for (i in 1:length(universe))
        {
        Counts[i,1] <- universe[i] %in% set1
        Counts[i,2] <- universe[i] %in% set2
       Counts[i,3] <- universe[i] %in% set3
       }

         vennDiagram( vennCounts(Counts) )}

       Diagram(set1, set2, set3, c("ORG1", "ORG2", "ORG3"))
        Venn
Run Code Online (Sandbox Code Playgroud)

小智 7

你也可以用limma完成这项壮举.请参阅下面的示例.

这个想法与您发布的代码基本完全相同,但它没有被包装到函数中(因此可能稍微容易调试).

你能用它来处理下面的代码吗?如果没有,请发布您可能收到的错误消息和警告.

# Load the library
library(limma)

# Generate example data
set1<-letters[1:5]
set2<-letters[4:8]
set3<-letters[5:9]

# What are the possible letters in the universe?
universe <- sort(unique(c(set1, set2, set3)))

# Generate a matrix, with the sets in columns and possible letters on rows
Counts <- matrix(0, nrow=length(universe), ncol=3)
# Populate the said matrix
for (i in 1:length(universe)) {
   Counts[i,1] <- universe[i] %in% set1
   Counts[i,2] <- universe[i] %in% set2
   Counts[i,3] <- universe[i] %in% set3
}

# Name the columns with the sample names
colnames(Counts) <- c("set1","set2","set3")

# Specify the colors for the sets
cols<-c("Red", "Green", "Blue")
vennDiagram(vennCounts(Counts), circle.col=cols)
Run Code Online (Sandbox Code Playgroud)

代码应该给出类似于以下内容的图:

在此输入图像描述

  • 来自CRAN的包"limma"似乎不适用于R 3.1.1,但我使用`source("http://bioconductor.org/biocLite.R")``biocLite("limma")使用它)` (2认同)