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

Puriney's Notes

Puriney=purine+Y, my Wonderland

 
 
 

日志

 
 

【转载】用R画韦恩图(文氏图)  

2012-08-25 23:06:37|  分类: 默认分类 |  标签: |举报 |字号 订阅

  下载LOFTER 我的照片书  |

venn                  package:gplots                   R Documentation

Plot a Venn diagram

Description:

     Plot a Venn diagrams for up to 5 sets

Usage:

     venn(data, universe=NA, small=0.7, showSetLogicLabel=FALSE,
          simplify=FALSE, show.plot=TRUE)

     ##data是一个vector组成的list 或者一个数据框,

     ##universe限定整个韦恩图的样本范围

    ##samll显示的counts的大小

    ##showSetLogicLabel是逻辑值,是否显示组标,如0000,0001,……

    ##show.plot是否画图
    

    ## S3 method for class 'venn':
     plot(x, y, ..., small=0.7, showSetLogicLabel=FALSE,
               simplify=FALSE)
    ##可以讲venn()结果存到变量,然后用plot画出图像。

 
Arguments:

  data,x: Either a list list containing vectors of names or indices of
          group members, or a data frame containing boolean indicators
          of group membership (see below)

universe: Subset of valid name/index elements. Values ignore values in
          code not in this list will be ignored. Use 'NA' to use all
          elements of 'data' (the default).

   small: Character scaling of the smallest group counts

showSetLogicLabel: Logical flag indicating whether the internal group
          label should be displayed

simplify: Logical flag indicating whether unobserved groups should be
          omitted.

show.plot: Logical flag indicating whether the plot should be
          displayed.  If false, simply returns the group count matrix.

   y,...: Ignored

example

     ## Example using a list of item names belonging to the
     ## specified group.
     ##
    
     ## construct some fake gene names..
     oneName <- function() paste(sample(LETTERS,5,replace=TRUE),collapse="")
     geneNames <- replicate(1000, oneName())
                           
     ##
     GroupA <- sample(geneNames, 400, replace=FALSE)
     GroupB <- sample(geneNames, 750, replace=FALSE)
     GroupC <- sample(geneNames, 250, replace=FALSE)
     GroupD <- sample(geneNames, 300, replace=FALSE)
     input  <-list(GroupA,GroupB,GroupC,GroupD)
     input
     venn(input)
    

     ## Limit  universe(限定总的范围)
     tmp <- venn(input, universe=geneNames[1:100])
     tmp
    

     ## Example to determine which elements are in A and B but not in
     ## C and D: first determine the universe, then form indicator columns
     ## and perform intersections on these.  R allows using the set operations
     ## directly, but some might find this approach more intuitive.
     ##
    
     universe <- unique(c(GroupA,GroupB,GroupC,GroupD))

    #unique是去重,求并集 ;%in%是求交集
     GroupA.l <-universe %in% GroupA
     GroupB.l <-universe %in% GroupB
     GroupC.l <-universe %in% GroupC
     GroupD.l <-universe %in% GroupD
    
     ## Genes that are in GroupA and in GroupB but not in GroupD (unification
     ## of sets III0 and II00 in the venn diagram:
     universe[GroupA.l & GroupB.l & !GroupD.l]
    
     ##
     ## Alternatively: construct a function to test for the pattern you want.
     ##
     test <- function(x) (x %in% GroupA) & (x %in% GroupB) & !(x %in% GroupC)
     universe[ test(universe) ]



PS: VennDiagram R  package

library(VennDiagram)

venn.diagram(

             x = list(

                     I = c(1:60, 61:105, 106:140, 141:160, 166:175, 176:180, 181:205, 206:220),

                     IV = c(531:605, 476:530, 336:375, 376:405, 181:205, 206:220, 166:175, 176:180),

                     II = c(61:105, 106:140, 181:205, 206:220, 221:285, 286:335, 336:375, 376:405),

                     III = c(406:475, 286:335, 106:140, 141:160, 166:175, 181:205, 336:375, 476:530),

          G = c(231:280, 111:120, 121:140, 201:230)

                     ),

             filename="x.tiff",

             col = "black",

             lty = 1,

             lwd = 4,

             #fill = c("cornflowerblue", "green", "yellow", "darkorchid1","red"),

             alpha = 0.50,

             #label.col = c("orange", "white", "darkorchid4", "white", "white", "white", "white", "white", "darkblue", "white", "white", "white", "white", "darkgreen", "white"),

             cex = 2.5,

             fontfamily = "serif",

             fontface = "bold",

             #cat.col = c("darkblue", "darkgreen", "orange", "darkorchid4","darkred"),

             #cat.cex = 2.5,

             #cat.fontfamily = "serif"

             );

  评论这张
 
阅读(1202)| 评论(0)
推荐 转载

历史上的今天

评论

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

页脚

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