Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/68.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何用R绘制维恩图_R_Venn Diagram - Fatal编程技术网

如何用R绘制维恩图

如何用R绘制维恩图,r,venn-diagram,R,Venn Diagram,我有三个ID列表 我想比较3个列表,并绘制一个维恩图。在获得的维恩图中,我将在交叉点显示的不是数字,而是ID。 我需要在R中这样做,但我真的不知道怎么做。 你能帮我吗? 这是我的密码。它是有效的,但只显示数字,我会将“术语”显示到交叉点 set1 <- unique(goterm1) set2 <- unique(goterm2) set3 <- unique(goterm3) require(limma)

我有三个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

set1你也可以用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)
#加载库
图书馆(林玛)
#生成示例数据
set1此答案使用的是“s
trans\n
功能。这是一个在我的工作流程中有意义的包装,但我认为可以在这里应用

安装:

library(devtools)
install_github("qdapDictionaries", "trinker")
install_github("qdap", "trinker")
set1 <- letters[1:5]
set2 <- letters[4:8]
set3 <- letters[5:9]

## reshapes the list of vectors to a data frame (unique is not needed)
dat <- list2df(list(set1 = set1, set2 = set2, set3 = set3), "word", "set")
trans_venn(dat$word, dat$set)
将其应用于您的数据:

library(devtools)
install_github("qdapDictionaries", "trinker")
install_github("qdap", "trinker")
set1 <- letters[1:5]
set2 <- letters[4:8]
set3 <- letters[5:9]

## reshapes the list of vectors to a data frame (unique is not needed)
dat <- list2df(list(set1 = set1, set2 = set2, set3 = set3), "word", "set")
trans_venn(dat$word, dat$set)

set1这可以通过使用我的r包来完成,如下所示:

set1 <- letters[1:5]
set2 <- letters[4:8]
set3 <- letters[5:9]

library(eulerr)

plot(euler(list(A = set1, B = set2, C = set3)))

set1 venneuler软件包应该能够帮助您;如果不是的话,Venniagram软件包更具可定制性。不过,你很可能需要事先计算出你感兴趣的比例。谢谢,我已经尝试了这两种方法,但都没有结果。然而,我还没有看到任何好的例子来学习它。现在你需要发布
dput(goterm1);dput(goterm2);dput(goterm2)
来自CRAN的包
limma
似乎不适用于R3.1.1,但我使用
源代码(“http://bioconductor.org/biocLite.R”
biocLite(“limma”)
这似乎是一个非常好用的功能,但用户无法设置圆圈的颜色:(更新:可设置颜色:绘图(欧拉(列表(A=set1,B=set2,C=set3)),填充=C(“红色”、“蓝色”、“绿色”))