注册 登录  
 加关注
   显示下一条  |  关闭
温馨提示!由于新浪微博认证机制调整,您的新浪微博帐号绑定已过期,请重新绑定!立即重新绑定新浪微博》  |  关闭

云之南

风声,雨声,读书声,声声入耳;家事,国事,天下事,事事关心

 
 
 

日志

 
 
关于我

专业背景:计算机科学 研究方向与兴趣: JavaEE-Web软件开发, 生物信息学, 数据挖掘与机器学习, 智能信息系统 目前工作: 基因组, 转录组, NGS高通量数据分析, 生物数据挖掘, 植物系统发育和比较进化基因组学

网易考拉推荐

How can I generate a Venn diagram in R?  

2011-09-09 12:49:58|  分类: R&Bioconductor |  标签: |举报 |字号 订阅

  下载LOFTER 我的照片书  |
http://bioinfogp.cnb.csic.es/tools/venny/index.html   
输入数据直接能画出不,不过好像只能画4个列表

http://www.ats.ucla.edu/stat/r/faq/venn.htm

How can I generate a Venn diagram in R?

Venn diagrams are a very commonly used graphing technique that illustrates levels of overlap between groups in data. They can be created in R using code written as part of the Bioconductor Project. We are following the directions supplied here for installing a package for linear models for microarray data (LIMMA). To use this code, we will use the source command in R to access the code.


source("http://www.bioconductor.org/biocLite.R")

After running this, we can examine what has been added to our workspace and investigate the nature of these objects.


ls()    [1] "biocinstall"             "biocinstallPkgGroups"     [3] "biocinstallRepos"        "biocLite"                 [5] "getBioC"                 "sourceBiocinstallScript"    class(biocLite)    [1] "function"  

The next step in the installation is a call to the biocLite function:


biocLite("limma")

The output from these calls indicates the installation of the limma package.  Finally, we need to load this package.


library(limma)

We can now use the commands in this package for generating Venn diagrams. The data needed for a Venn diagram consists of a set of binary variables indicating membership.  We will be using the hsb2 dataset consisting of data from 200 students including scores from writing, reading, and math tests.  We will create indicators for "high" values in each of these variables and generate Venn diagrams that tell us about the degree of overlap in high math, writing, and reading scores. 

http://www.ats.ucla.edu/stat/R/notes/hsb2.csv

部分数据:

id female race ses schtyp prog read write math science socst
70 male white low public general 57 52 41 47 57
121 female white middle public vocation 68 59 53 63 61
86 male white high public general 44 33 54 58 31
141 male white high public vocation 63 44 47 53 56
172 male white middle public academic 47 52 57 53 61
113 male white middle public academic 44 52 51 63 61
50 male african-amer middle public general 50 59 42 53 61
11 male hispanic middle public academic 34 46 45 39 36
84 male white middle public general 63 57 54 58 51
48 male african-amer middle public academic 57 55 52 50 51
75 male white middle public vocation 60 46 51 53 61
60 male white middle public academic 57 65 51 63 61
95 male white high public academic 73 60 71 61 71
104 male white high public academic 54 63 57 55 46
38 male african-amer low public academic 45 57 50 31 56
115 male white low public general 42 49 43 50 56
76 male white high public academic 47 52 51 50 56
195 male white middle private general 57 57 60 58 56
114 male white high public academic 68 65 62 55 61
85 male white middle public general 55 39 57 53 46
167 male white middle public general 63 49 35 66 41
143 male white middle public vocation 63 63 75 72 66
41 male african-amer middle public academic 50 40 45 55 56
20 male hispanic high public academic 60 52 57 61 61
12 male hispanic middle public vocation 37 44 45 39 46
53 male african-amer middle public vocation 34 37 46 39 31
154 male white high public academic 65 65 66 61 66
178 male white middle private vocation 47 57 57 58 46
196 male white high private academic 44 38 49 39 46
29 male asian low public general 52 44 49 55 41
126 male white middle public general 42 31 57 47 51
103 male white high public academic 76 52 64 64 61
192 male white high private academic 65 67 63 66 71
150 male white middle public vocation 42 41 57 72 31
199 male white high private academic 52 59 50 61 61
144 male white high public general 60 65 58 61 66
200 male white middle private academic 68 54 75 66 66
80 male white high public academic 65 62 68 66 66
16 male hispanic low public vocation 47 31 44 36 36
153 male white middle public vocation 39 31 40 39 51
176 male white middle private academic 47 47 41 42 51
177 male white middle private academic 55 59 62 58 51
168 male white middle public academic 52 54 57 55 51
40 male african-amer low public general 42 41 43 50 41
62 male white high public general 65 65 48 63 66
169 male white low public general 55 59 63 69 46
49 male african-amer high public vocation 50 40 39 49 47
136 male white middle public academic 65 59 70 63 51
189 male white middle private academic 47 59 63 53 46
7 male hispanic middle public academic 57 54 59 47 51
27 male asian middle public academic 53 61 61 57 56
128 male white high public academic 39 33 38 47 41
21 male hispanic middle public general 44 44 61 50 46
183 male white middle private academic 63 59 49 55 71
132 male white middle public academic 73 62 73 69 66
15 male hispanic high public vocation 39 39 44 26 42
67 male white low public vocation 37 37 42 33 32
22 male hispanic middle public vocation 42 39 39 56 46
185 male white middle private academic 63 57 55 58 41
9 male hispanic middle public vocation 48 49 52 44 51
181 male white middle private academic 50 46 45 58 61
170 male white high public academic 47 62 61 69 66
134 male white low public general 44 44 39 34 46
108 male white middle public general 34 33 41 36 36
197 male white high private academic 50 42 50 36 61
140 male white middle public vocation 44 41 40 50 26
171 male white middle public academic 60 54 60 55 66
107 male white low public vocation 47 39 47 42 26
81 male white low public academic 63 43 59 65 44
18 male hispanic middle public vocation 50 33 49 44 36

 

hsb2<-read.table("http://www.ats.ucla.edu/stat/R/notes/hsb2.csv", sep=',', header=T)  attach(hsb2)    hw<-(write>=60)  hm<-(math >=60)  hr<-(read >=60)  c3<-cbind(hw, hm, hr)


Next, we can use the vennCounts command to impose the structure needed to generate the Venn diagram.


a <- vennCounts(c3)  a         hw hm hr Counts  [1,]  0  0  0    113  [2,]  0  0  1     18  [3,]  0  1  0      8  [4,]  0  1  1      8  [5,]  1  0  0     12  [6,]  1  0  1      8  [7,]  1  1  0     11  [8,]  1  1  1     22  attr(,"class")  [1] "VennCounts"

We can now generate our Venn diagram with the vennDiagram command:


vennDiagram(a)    How can I generate a Venn diagram in R? - 云之南 - 云之南  

While some of the options for the vennDiagram command are specific to tests run on microarray data, we can change some of the formatting.  Below, we add names to the groups, we change the relative size of the labels and counts, and we opt for the counts to appear in red. 


vennDiagram(a, include = "both", names = c("High Writing", "High Math", "High Reading"), cex = 1, counts.col = "red")    How can I generate a Venn diagram in R? - 云之南 - 云之南  

We could opt to present just two groups in this way, but it is not possible to add a fourth. Note that the size of the areas of overlap do not coincide with the relative counts. It is also worth noting that the areas in these Venn diagrams may suggest overlap where there, in fact, is none. The example below illustrates this.


g1 <- c(rep(0, 6), rep(1, 3))  g2 <- c(rep(1, 6), rep(0, 3))  g <- cbind(g1, g2)  c <- vennCounts(g)  vennDiagram(c)    How can I generate a Venn diagram in R? - 云之南 - 云之南  
  评论这张
 
阅读(1784)| 评论(0)
推荐 转载

历史上的今天

在LOFTER的更多文章

评论

<#--最新日志,群博日志--> <#--推荐日志--> <#--引用记录--> <#--博主推荐--> <#--随机阅读--> <#--首页推荐--> <#--历史上的今天--> <#--被推荐日志--> <#--上一篇,下一篇--> <#-- 热度 --> <#-- 网易新闻广告 --> <#--右边模块结构--> <#--评论模块结构--> <#--引用模块结构--> <#--博主发起的投票-->
 
 
 
 
 
 
 
 
 
 
 
 
 
 

页脚

网易公司版权所有 ©1997-2016