diff --git a/DESCRIPTION b/DESCRIPTION index aa6ae2c..62634ff 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -20,10 +20,11 @@ Imports: stats, methods, grDevices, - scales + scales, + grid License: MIT + file LICENSE LazyData: true VignetteBuilder: knitr Suggests: knitr -RoxygenNote: 5.0.1 +RoxygenNote: 6.0.1 diff --git a/NAMESPACE b/NAMESPACE index 61251e7..8c12311 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -16,6 +16,7 @@ import(stats) import(utils) importFrom(grid,gpar) importFrom(grid,grid.draw) +importFrom(grid,grid.grab) importFrom(grid,grid.layout) importFrom(grid,grid.newpage) importFrom(grid,legendGrob) diff --git a/R/UpSet.plot.R b/R/UpSet.plot.R index 4e3ac5e..ecdd3ea 100644 --- a/R/UpSet.plot.R +++ b/R/UpSet.plot.R @@ -117,11 +117,11 @@ BaseBoxPlot <- function(box_plot, position, size_plot_height, Main_bar_plot, Mat } vp = vplayout(bar_top:matrix_bottom, matrix_and_mainbar_left:matrix_and_mainbar_right) pushViewport(vp) - grid.draw(arrangeGrob(Main_bar_plot, Matrix_plot, heights = hratios)) + grid.draw(arrangeGrob(Main_bar_plot, Matrix_plot, heights = hratios, name = "main")) popViewport() vp = vplayout(size_plot_height:matrix_bottom, size_bar_left:size_bar_right) pushViewport(vp) - grid.draw(arrangeGrob(Size_plot)) + grid.draw(arrangeGrob(Size_plot, name = "size")) popViewport() if(is.null(set_metadata) == F){ for(i in 1:length(set_metadata_plots)){ @@ -136,18 +136,18 @@ BaseBoxPlot <- function(box_plot, position, size_plot_height, Main_bar_plot, Mat vp = vplayout(size_plot_height:matrix_bottom, metadata_left:metadata_right) pushViewport(vp) - grid.draw(arrangeGrob(set_metadata_plots[[i]])) + grid.draw(arrangeGrob(set_metadata_plots[[i]], name = "metadata")) popViewport() } } vp = vplayout(att_top:att_bottom, matrix_and_mainbar_left:matrix_and_mainbar_right) pushViewport(vp) - grid.draw(arrangeGrob(box_plot[[1]])) + grid.draw(arrangeGrob(box_plot[[1]], name = "boxplot1")) popViewport() if(length(box_plot) == 2){ vp = vplayout((att_bottom + 10):(att_bottom + 25), matrix_and_mainbar_left:matrix_and_mainbar_right) pushViewport(vp) - grid.draw(arrangeGrob(box_plot[[2]])) + grid.draw(arrangeGrob(box_plot[[2]], name = "boxplot2")) popViewport() } } @@ -198,11 +198,11 @@ NoAttBasePlot <- function(legend, size_plot_height, Main_bar_plot, Matrix_plot, } vp = vplayout(top:bottom, matrix_and_mainbar_left:matrix_and_mainbar_right) pushViewport(vp) - grid.draw(arrangeGrob(Main_bar_plot, Matrix_plot, heights = hratios)) + grid.draw(arrangeGrob(Main_bar_plot, Matrix_plot, heights = hratios, name = "main")) popViewport() vp = vplayout(size_plot_height:bottom, size_bar_left:size_bar_right) pushViewport(vp) - grid.draw(arrangeGrob(Size_plot)) + grid.draw(arrangeGrob(Size_plot, name = "size")) popViewport() if(is.null(set_metadata) == F){ for(i in 1:length(set_metadata_plots)){ @@ -217,14 +217,14 @@ NoAttBasePlot <- function(legend, size_plot_height, Main_bar_plot, Matrix_plot, vp = vplayout(size_plot_height:bottom, metadata_left:metadata_right) pushViewport(vp) - grid.draw(arrangeGrob(set_metadata_plots[[i]])) + grid.draw(arrangeGrob(set_metadata_plots[[i]], name = "metadata")) popViewport() } } if((is.null(legend) == F) && (query_legend != tolower("none"))){ vp = vplayout(legend_top:legend_bottom, matrix_and_mainbar_left:matrix_and_mainbar_right) pushViewport(vp) - grid.draw(arrangeGrob(legend)) + grid.draw(arrangeGrob(legend, name = "legend")) popViewport() } } @@ -263,11 +263,11 @@ BaseCustomPlot <- function(attribute_plots, plots, position, size_plot_height, M pushViewport(viewport(layout = grid.layout(custom_bottom,matrix_and_mainbar_right))) vp = vplayout(bar_top:matrix_bottom, matrix_and_mainbar_left:matrix_and_mainbar_right) pushViewport(vp) - grid.draw(arrangeGrob(Main_bar_plot, Matrix_plot, heights = hratios)) + grid.draw(arrangeGrob(Main_bar_plot, Matrix_plot, heights = hratios, name = "main")) popViewport() vp = vplayout(size_plot_height:matrix_bottom, size_bar_left:size_bar_right) pushViewport(vp) - grid.draw(arrangeGrob(Size_plot)) + grid.draw(arrangeGrob(Size_plot, name = "size")) popViewport() if(is.null(set_metadata) == F){ for(i in 1:length(set_metadata_plots)){ @@ -282,34 +282,34 @@ BaseCustomPlot <- function(attribute_plots, plots, position, size_plot_height, M vp = vplayout(size_plot_height:matrix_bottom, metadata_left:metadata_right) pushViewport(vp) - grid.draw(arrangeGrob(set_metadata_plots[[i]])) + grid.draw(arrangeGrob(set_metadata_plots[[i]], name = "metadata")) popViewport() } } if((is.null(legend) == F) && (q_legend == tolower("bottom"))){ vp = vplayout(custom_top:(custom_bottom - 5), 1:matrix_and_mainbar_right) pushViewport(vp) - grid.draw(do.call(arrangeGrob, c(plots, ncol = attribute_plots$ncols))) + grid.draw(do.call(arrangeGrob, c(plots, ncol = attribute_plots$ncols, name = "attribute"))) popViewport() vp = vplayout((custom_bottom - 4):custom_bottom, 1:matrix_and_mainbar_right) pushViewport(vp) - grid.draw(arrangeGrob(legend)) + grid.draw(arrangeGrob(legend, name = "legend")) popViewport() } else if((is.null(legend) == F) && (q_legend == tolower("top"))){ vp = vplayout(custom_top:custom_bottom, 1:matrix_and_mainbar_right) pushViewport(vp) - grid.draw(do.call(arrangeGrob, c(plots, ncol = attribute_plots$ncols))) + grid.draw(do.call(arrangeGrob, c(plots, ncol = attribute_plots$ncols, name = "attribute"))) popViewport() vp = vplayout((bar_top-5):(bar_top-1), 1:matrix_and_mainbar_right) pushViewport(vp) - grid.draw(arrangeGrob(legend)) + grid.draw(arrangeGrob(legend, name = "legend")) popViewport() } else{ vp = vplayout(custom_top:custom_bottom, 1:matrix_and_mainbar_right) pushViewport(vp) - grid.draw(do.call(arrangeGrob, c(plots, ncol = attribute_plots$ncols))) + grid.draw(do.call(arrangeGrob, c(plots, ncol = attribute_plots$ncols, name = "attribute"))) popViewport() } # print(attribute_plots$plot, vp = vplayout(attribute_plots$rows, attribute_plots$cols), newpage = F) diff --git a/R/upset.R b/R/upset.R index 2212308..a557555 100644 --- a/R/upset.R +++ b/R/upset.R @@ -110,7 +110,8 @@ #' @import stats #' @import methods #' @import grDevices -#' @import scales +#' @import scales +#' @importFrom grid grid.grab #' @export upset <- function(data, nsets = 5, nintersects = 40, sets = NULL, keep.order = F, set.metadata = NULL, intersections = NULL, matrix.color = "gray23", main.bar.color = "gray23", mainbar.y.label = "Intersection Size", mainbar.y.max = NULL, @@ -260,4 +261,6 @@ upset <- function(data, nsets = 5, nintersects = 40, sets = NULL, keep.order = F expression, att.pos, first.col, att.color, AllQueryData, attribute.plots, legend, query.legend, BoxPlots, Set_names, set.metadata, set.metadata.plots) + # Return a gTree so plot can be assigned to a variable + invisible(grid.grab()) } \ No newline at end of file diff --git a/README.md b/README.md index 39ada0d..981ff7d 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,3 @@ -# UpSetR [![Travis-CI Build Status](https://travis-ci.org/hms-dbmi/UpSetR.svg?branch=master)](https://travis-ci.org/hms-dbmi/UpSetR) [![](http://www.r-pkg.org/badges/version/UpSetR)](https://cran.r-project.org/package=UpSetR) [![](http://cranlogs.r-pkg.org/badges/grand-total/UpSetR)](http://cranlogs.r-pkg.org/badges/grand-total/UpSetR) - ## Technique UpSetR generates static [UpSet](http://vcg.github.io/upset/) plots. The UpSet technique visualizes set intersections in a matrix layout and introduces aggregates based on groupings and queries. The matrix layout enables the effective representation of associated data, such as the number of elements in the aggregates and intersections, as well as additional summary statistics derived from subset or element attributes. @@ -22,6 +20,15 @@ The original technique and the interactive visualization tool implementing the a > IEEE Transactions on Visualization and Computer Graphics (InfoVis '14), vol. 20, no. 12, pp. 1983–1992, 2014. > doi: https://doi.org/10.1109/TVCG.2014.2346248 +## THIS VERSION + +This is a fork of the [main repo](https://github.com/hms-dbmi/UpSetR) and makes minor edits to allow assigning the plots to variables which can then be called later and if required incorporated into more complex figures. This is outlined in my [pull request (#100)](https://github.com/hms-dbmi/UpSetR/pull/100) but at the time of writing it has not been merged. To maintain my own code I am therefore keeping this repo. + +To download this version of the code using [devtools](https://cran.r-project.org/package=devtools) you can use + +```R +devtools::install_github("g-thomson/UpSetR") +``` ## Sample Data @@ -81,16 +88,5 @@ list(query = intersects, params = list("Noir")))) ``` -## Download -Install the latest released version from CRAN -```R -install.packages("UpSetR") -``` - -Download the latest development code of UpSetR from GitHub using [devtools](https://cran.r-project.org/package=devtools) with - -```R -devtools::install_github("hms-dbmi/UpSetR") -``` diff --git a/man/elements.Rd b/man/elements.Rd index 03b0dd1..d8420a0 100644 --- a/man/elements.Rd +++ b/man/elements.Rd @@ -19,4 +19,3 @@ A query paramter to visualize specific elements of interest if queries = active \note{ See examples section of upset function on how to use this function in the queries parameter. } - diff --git a/man/fromExpression.Rd b/man/fromExpression.Rd index 10f42fa..175947c 100644 --- a/man/fromExpression.Rd +++ b/man/fromExpression.Rd @@ -15,4 +15,3 @@ A function to convert an expression to a data frame compatible with UpSetR. \note{ See "Basic Usage" vignette for an example on how to use this function in UpSetR. } - diff --git a/man/fromList.Rd b/man/fromList.Rd index 63397bb..f5f4ce5 100644 --- a/man/fromList.Rd +++ b/man/fromList.Rd @@ -15,4 +15,3 @@ A function to convert a list of named vectors to a data frame compatible with Up \note{ See "Basic Usage" vignette for an example on how to use this function in UpSetR. } - diff --git a/man/histogram.Rd b/man/histogram.Rd index 7df7d80..006c7e9 100644 --- a/man/histogram.Rd +++ b/man/histogram.Rd @@ -17,4 +17,3 @@ A pre-made histogram that can be added to custom.plot paramter. \note{ See examples section for upset function on how to use custom.plot parameter } - diff --git a/man/intersects.Rd b/man/intersects.Rd index c20573b..beffc73 100644 --- a/man/intersects.Rd +++ b/man/intersects.Rd @@ -19,4 +19,3 @@ A query paramter to visualize elements contained in specific intersections \note{ See examples section of upset function on how to use this function in the queries parameter. } - diff --git a/man/scatter_plot.Rd b/man/scatter_plot.Rd index ef6a6bf..cff0be2 100644 --- a/man/scatter_plot.Rd +++ b/man/scatter_plot.Rd @@ -19,4 +19,3 @@ A pre-made scatter plot that can be added to the custom.plot paramter. \note{ See examples section for upset function on how to use custom.plot parameter. } - diff --git a/man/upset.Rd b/man/upset.Rd index 8f1dc7d..7740109 100644 --- a/man/upset.Rd +++ b/man/upset.Rd @@ -176,4 +176,3 @@ Original UpSet Website: \url{http://vcg.github.io/upset/about/} UpSetR github for additional examples: \url{http://github.com/hms-dbmi/UpSetR} } -