From 35a34e18b633f5446ed29e4129ccc1039c177b49 Mon Sep 17 00:00:00 2001 From: guangchuang yu Date: Tue, 24 Apr 2018 14:34:43 +0800 Subject: [PATCH 1/2] arrange ID --- R/UpSet.plot.R | 47 +++++++++++++++++++++++++++-------------------- 1 file changed, 27 insertions(+), 20 deletions(-) diff --git a/R/UpSet.plot.R b/R/UpSet.plot.R index 27ab9d8..edf942c 100644 --- a/R/UpSet.plot.R +++ b/R/UpSet.plot.R @@ -110,7 +110,7 @@ BaseBoxPlot <- function(box_plot, position, size_plot_height, Main_bar_plot, Mat metadata_left <- 1 } if (newpage) { - grid.newpage() + grid.null() } if(length(box_plot) == 1){ pushViewport(viewport(layout = grid.layout(135,matrix_and_mainbar_right))) @@ -120,11 +120,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 = arrange_id())) 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 = arrange_id())) popViewport() if(!is.null(set_metadata)){ for(i in 1:length(set_metadata_plots)){ @@ -139,18 +139,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 = arrange_id())) 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 = arrange_id())) 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 = arrange_id())) popViewport() } } @@ -188,7 +188,7 @@ NoAttBasePlot <- function(legend, size_plot_height, Main_bar_plot, Matrix_plot, metadata_left <- 1 } if (newpage) { - grid.newpage() + grid.null() } if((!is.null(legend)) && (query_legend != tolower("none"))){ if(query_legend == tolower("top")){ @@ -203,11 +203,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 = arrange_id())) 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 = arrange_id())) popViewport() if(!is.null(set_metadata)){ for(i in 1:length(set_metadata_plots)){ @@ -222,14 +222,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 = arrange_id())) popViewport() } } if((!is.null(legend)) && (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 = arrange_id())) popViewport() } } @@ -265,16 +265,16 @@ BaseCustomPlot <- function(attribute_plots, plots, position, size_plot_height, M custom_bottom <- custom_bottom + 5 } if (newpage) { - grid.newpage() + grid.null() } 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 = arrange_id())) 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 = arrange_id())) popViewport() if(!is.null(set_metadata)){ for(i in 1:length(set_metadata_plots)){ @@ -289,34 +289,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 = arrange_id())) popViewport() } } if((!is.null(legend)) && (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 = arrange_id()))) popViewport() vp = vplayout((custom_bottom - 4):custom_bottom, 1:matrix_and_mainbar_right) pushViewport(vp) - grid.draw(arrangeGrob(legend)) + grid.draw(arrangeGrob(legend, name = arrange_id())) popViewport() } else if((!is.null(legend)) && (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 = arrange_id()))) 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 = arrange_id())) 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 = arrange_id()))) popViewport() } # print(attribute_plots$plot, vp = vplayout(attribute_plots$rows, attribute_plots$cols), newpage = F) @@ -325,3 +325,10 @@ BaseCustomPlot <- function(attribute_plots, plots, position, size_plot_height, M # printCustom <- function(attribute_plots){ # print(attribute_plots$plot, vp = vplayout(attribute_plots$rows, attribute_plots$cols), newpage = F) # } + + +arrange_id <- function() { + paste0('arrange', annotation_id()) +} + +annotation_id <- getFromNamespace("annotation_id", "ggplot2") From 58cc26f356405dfee96be03934fd4f3db10d2ced Mon Sep 17 00:00:00 2001 From: guangchuang yu Date: Tue, 24 Apr 2018 14:39:30 +0800 Subject: [PATCH 2/2] back to grid.newpage --- NAMESPACE | 3 ++- R/UpSet.plot.R | 6 +++--- man/upset.Rd | 4 ++-- 3 files changed, 7 insertions(+), 6 deletions(-) diff --git a/NAMESPACE b/NAMESPACE index bc60d7e..0a3bcf2 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -1,6 +1,7 @@ # Generated by roxygen2: do not edit by hand S3method(print,upset) +S3method(summary,upset) export(elements) export(fromExpression) export(fromList) @@ -18,7 +19,7 @@ import(utils) importFrom(grid,gpar) importFrom(grid,grid.draw) importFrom(grid,grid.layout) -importFrom(grid,grid.null) +importFrom(grid,grid.newpage) importFrom(grid,legendGrob) importFrom(grid,popViewport) importFrom(grid,pushViewport) diff --git a/R/UpSet.plot.R b/R/UpSet.plot.R index edf942c..1851b0c 100644 --- a/R/UpSet.plot.R +++ b/R/UpSet.plot.R @@ -110,7 +110,7 @@ BaseBoxPlot <- function(box_plot, position, size_plot_height, Main_bar_plot, Mat metadata_left <- 1 } if (newpage) { - grid.null() + grid.newpage() } if(length(box_plot) == 1){ pushViewport(viewport(layout = grid.layout(135,matrix_and_mainbar_right))) @@ -188,7 +188,7 @@ NoAttBasePlot <- function(legend, size_plot_height, Main_bar_plot, Matrix_plot, metadata_left <- 1 } if (newpage) { - grid.null() + grid.newpage() } if((!is.null(legend)) && (query_legend != tolower("none"))){ if(query_legend == tolower("top")){ @@ -265,7 +265,7 @@ BaseCustomPlot <- function(attribute_plots, plots, position, size_plot_height, M custom_bottom <- custom_bottom + 5 } if (newpage) { - grid.null() + grid.newpage() } 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) diff --git a/man/upset.Rd b/man/upset.Rd index 6a781e3..03b4ff8 100644 --- a/man/upset.Rd +++ b/man/upset.Rd @@ -30,7 +30,7 @@ upset(data, nsets = 5, nintersects = 40, sets = NULL, keep.order = F, \item{keep.order}{Keep sets in the order entered using the sets parameter. The default is FALSE, which orders the sets by their sizes.} -\item{set.metadata}{Metadata that offers insight to an attribute of the sets. Input should be a data frame where the first column is set names, and the +\item{set.metadata}{Metadata that offers insight to an attribute of the sets. Input should be a data frame where the first column is set names, and the remaining columns are attributes of those sets. To learn how to use this parameter it is highly suggested to view the set metadata vignette. The link can be found on the package's GitHub page.} @@ -165,7 +165,7 @@ upset(movies, attribute.plots = attributeplots, list(query = intersects, params = list("Drama"), color= "red"), list(query = elements, params = list("ReleaseDate", 1990, 1991, 1992))), main.bar.color = "yellow") - + } \references{ Lex et al. (2014). UpSet: Visualization of Intersecting Sets