[R-gregmisc-users] SF.net SVN: r-gregmisc:[1942] trunk/gplots
Brought to you by:
warnes
From: <wa...@us...> - 2015-04-23 19:58:51
|
Revision: 1942 http://sourceforge.net/p/r-gregmisc/code/1942 Author: warnes Date: 2015-04-23 19:58:44 +0000 (Thu, 23 Apr 2015) Log Message: ----------- - The returned object from venn() now includes a 'interesection' attribution containing a list of which items are in each set intersection. This can be turned off by settting 'intersection=FALSE'. Modified Paths: -------------- trunk/gplots/R/venn.R trunk/gplots/man/venn.Rd Modified: trunk/gplots/R/venn.R =================================================================== --- trunk/gplots/R/venn.R 2015-04-23 19:09:17 UTC (rev 1941) +++ trunk/gplots/R/venn.R 2015-04-23 19:58:44 UTC (rev 1942) @@ -1,7 +1,7 @@ # This code plots Venn Diagrams for up to 5 sets. The # function getVennCounts is passed a list of vectors. # This is transformed into a table indicating the -# number of members for each intersection. This table +# number of intersections for each intersection. This table # is generated for any number of sets. # The function drawVennDiagram plots circles (up to three @@ -23,16 +23,19 @@ stop("Only indicator columns permitted") l <- lapply( l, function(x) which(as.logical(x))) - getVennCounts.list(l) + getVennCounts.list(l, universe=universe, verbose=verbose) } # l offers a list of arrays, their values are to # be tested for the size of their intersects. -getVennCounts.list<-function(l, universe=NA, verbose=F) { +getVennCounts.list<-function(l, universe=NA, verbose=F, intersections=TRUE) { if (verbose) cat("Interpreting data as list.\n") numSets<-length(l) result.table<-NULL result.table.names<-NULL + + memberList <- list() + # Iteration over all possible intersections involving all sets # or the complement (negation) of those sets. for (i in 0:(-1 + 2^numSets)) { @@ -104,8 +107,12 @@ sel<-NULL } + r.name<-paste(i2,collapse="") + if (intersections) { + memberList[[r.name]] <- sel + } + r<-length(sel) - r.name<-paste(i2,collapse="") result.row<-c(r,i2) dim(result.row)<-c(1,length(result.row)) rownames(result.row)<-c(r.name) @@ -132,6 +139,9 @@ else{ colnames(result.table)<-c("num",names(l)) } + if (intersections) { + attr(result.table,"intersections") <- memberList + } class(result.table) <- "venn" return(result.table) } @@ -144,9 +154,10 @@ small=0.7, showSetLogicLabel=FALSE, simplify=FALSE, - show.plot=TRUE) + show.plot=TRUE, + intersections=TRUE) { - counts <- getVennCounts(data, universe=universe) + counts <- getVennCounts(data, universe=universe, intersections=intersections) if(show.plot) drawVennDiagram(data=counts, Modified: trunk/gplots/man/venn.Rd =================================================================== --- trunk/gplots/man/venn.Rd 2015-04-23 19:09:17 UTC (rev 1941) +++ trunk/gplots/man/venn.Rd 2015-04-23 19:58:44 UTC (rev 1942) @@ -7,14 +7,14 @@ } \usage{ venn(data, universe=NA, small=0.7, showSetLogicLabel=FALSE, - simplify=FALSE, show.plot=TRUE) + simplify=FALSE, show.plot=TRUE, intersections=TRUE) \method{plot}{venn}(x, y, ..., small=0.7, showSetLogicLabel=FALSE, simplify=FALSE) } \arguments{ \item{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)} + of group intersections, or a data frame containing boolean indicators of + group intersectionship (see below)} \item{universe}{Subset of valid name/index elements. Values ignore values in code{data} not in this list will be ignored. Use \code{NA} to use all elements of \code{data} (the default).} @@ -25,13 +25,17 @@ should be omitted.} \item{show.plot}{Logical flag indicating whether the plot should be displayed. If false, simply returns the group count matrix.} + \item{intersections}{Logical flag indicating + if the returned object should have the attribute + "individuals.in.intersections" featuring for every set a list of + individuals that are assigned to it.} \item{y,...}{Ignored} } \details{ \code{data} should be either a named list of vectors containing character string names ("GeneAABBB", "GeneBBBCY", .., "GeneXXZZ") or - indexes of group members (1, 2, .., N), or a data frame containing - indicator variables (TRUE, FALSE, TRUE, ..) for group membership. + indexes of group intersections (1, 2, .., N), or a data frame containing + indicator variables (TRUE, FALSE, TRUE, ..) for group intersectionship. Group names will be taken from the component list element or column names. } @@ -39,7 +43,7 @@ Invisibly returns an object of class "venn", containing a matrix of all possible sets of groups, and the observed count of items belonging to each The fist column contains observed counts, subsequent columns - contain 0-1 indicators of group membership. + contain 0-1 indicators of group intersectionship. } \author{ Steffen Moeller \email{steffen\_mo...@gm...}, @@ -64,9 +68,9 @@ input <-list(GroupA,GroupB,GroupC,GroupD) input -venn(input) +tmp <- venn(input) +attr(tmp, "intersections") - ## ## Example using a list of item indexes belonging to the ## specified group. @@ -131,6 +135,14 @@ test <- function(x) (x \%in\% GroupA) & (x \%in\% GroupB) & !(x \%in\% GroupC) universe[ test(universe) ] +## +## Intriduced with gplots 2.16, the names of individuals for everz intersection +## is offered as an attribute to the retrun value. +## +a<-venn(list(1:5,3:8),show.plot=F,intersections=TRUE) +intersections<-attr(a,"intersections") +print(intersections) + } \keyword{hplot} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |