From ea70aa3a70c287822eedd7c88d83d26eaf5f3ee5 Mon Sep 17 00:00:00 2001 From: Jonathan Carroll Date: Thu, 19 Jul 2018 11:25:57 +0930 Subject: [PATCH 1/2] introduces title to plots (closes #76) updated NEWS minor differences in upset.Rd likely due to different roxygen versions NAMESPACE changes (not committed) likely due to roxygen versions/out of date build --- NEWS | 4 ++++ R/upset.R | 16 +++++++++++++++- man/upset.Rd | 12 +++++++++--- 3 files changed, 28 insertions(+), 4 deletions(-) diff --git a/NEWS b/NEWS index 4d8b481..22b9d4b 100644 --- a/NEWS +++ b/NEWS @@ -1,3 +1,7 @@ +Release v1.4.1 + +- Allow plot title with specified size and position (@jonocarroll, #76) + Release v1.4.0 - Allow custom y-axis label and scale diff --git a/R/upset.R b/R/upset.R index a8d373d..8df2bf2 100644 --- a/R/upset.R +++ b/R/upset.R @@ -9,6 +9,8 @@ #' @param 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. +#' @param title Plot title +#' @param title.pos Position of title in grid reference as a named vector. Default \code{c(x=0.65, y=0.95)}. #' @param intersections Specific intersections to include in plot entered as a list of lists. #' Ex: list(list("Set name1", "Set name2"), list("Set name1", "Set name3")). If data is entered into this parameter the only data shown on the UpSet plot #' will be the specific intersections listed. @@ -95,6 +97,10 @@ #' upset(movies, nsets = 7, nintersects = 30, mb.ratio = c(0.5, 0.5), #' order.by = c("freq", "degree"), decreasing = c(TRUE,FALSE)) #' +# upset(movies, nsets = 7, nintersects = 30, mb.ratio = c(0.5, 0.5), +# order.by = c("freq", "degree"), decreasing = c(TRUE,FALSE), +# title = "Movies", title.pos = c(x = 0.1, y = 0.95)) +#' #' upset(movies, sets = c("Drama", "Comedy", "Action", "Thriller", "Western", "Documentary"), #' queries = list(list(query = intersects, params = list("Drama", "Action")), #' list(query = between, params = list(1970, 1980), color = "red", active = TRUE))) @@ -113,7 +119,7 @@ #' @import grDevices #' @import scales #' @export -upset <- function(data, nsets = 5, nintersects = 40, sets = NULL, keep.order = F, set.metadata = NULL, intersections = NULL, +upset <- function(data, nsets = 5, nintersects = 40, sets = NULL, keep.order = F, set.metadata = NULL, title = "", title.pos = c(x = 0.65, y = 0.95), intersections = NULL, matrix.color = "gray23", main.bar.color = "gray23", mainbar.y.label = "Intersection Size", mainbar.y.max = NULL, sets.bar.color = "gray23", sets.x.label = "Set Size", point.size = 2.2, line.size = 0.7, mb.ratio = c(0.70,0.30), expression = NULL, att.pos = NULL, att.color = main.bar.color, order.by = c("freq", "degree"), @@ -135,6 +141,10 @@ upset <- function(data, nsets = 5, nintersects = 40, sets = NULL, keep.order = F "#CC79A7") } + ## ensure title.pos is conformant + if (!is.numeric(title.pos)) stop("title.pos must be numeric") + if (!identical(sort(names(title.pos)), c("x", "y"))) stop("title.pos requires a named vector with components 'x' and 'y'") + if(is.null(intersections) == F){ Set_names <- unique((unlist(intersections))) Sets_to_remove <- Remove(data, first.col, last.col, Set_names) @@ -280,6 +290,9 @@ upset <- function(data, nsets = 5, nintersects = 40, sets = NULL, keep.order = F AllQueryData = AllQueryData, attribute.plots = attribute.plots, legend = legend, + title = title, + title.pos = title.pos, + text.scale = text.scale, query.legend = query.legend, BoxPlots = BoxPlots, Set_names = Set_names, @@ -311,6 +324,7 @@ print.upset <- function(x, newpage = TRUE) { set_metadata = x$set.metadata, set_metadata_plots = x$set.metadata.plots, newpage = newpage) + grid::grid.text(x$title, x = x$title.pos[["x"]], y = x$title.pos[["y"]], gp = grid::gpar(fontsize = 16*x$text.scale)) } #' @export diff --git a/man/upset.Rd b/man/upset.Rd index 6a781e3..18496f5 100644 --- a/man/upset.Rd +++ b/man/upset.Rd @@ -5,7 +5,8 @@ \title{UpSetR Plot} \usage{ upset(data, nsets = 5, nintersects = 40, sets = NULL, keep.order = F, - set.metadata = NULL, intersections = NULL, matrix.color = "gray23", + set.metadata = NULL, title = "", title.pos = c(x = 0.65, y = 0.95), + intersections = NULL, matrix.color = "gray23", main.bar.color = "gray23", mainbar.y.label = "Intersection Size", mainbar.y.max = NULL, sets.bar.color = "gray23", sets.x.label = "Set Size", point.size = 2.2, line.size = 0.7, @@ -30,10 +31,14 @@ 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.} +\item{title}{Plot title} + +\item{title.pos}{Position of title in grid reference as a named vector. Default \code{c(x=0.65, y=0.95)}.} + \item{intersections}{Specific intersections to include in plot entered as a list of lists. Ex: list(list("Set name1", "Set name2"), list("Set name1", "Set name3")). If data is entered into this parameter the only data shown on the UpSet plot will be the specific intersections listed.} @@ -156,6 +161,7 @@ attributeplots <- list(gridrows = 55, upset(movies, nsets = 7, nintersects = 30, mb.ratio = c(0.5, 0.5), order.by = c("freq", "degree"), decreasing = c(TRUE,FALSE)) + upset(movies, sets = c("Drama", "Comedy", "Action", "Thriller", "Western", "Documentary"), queries = list(list(query = intersects, params = list("Drama", "Action")), list(query = between, params = list(1970, 1980), color = "red", active = TRUE))) @@ -165,7 +171,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 From 678b2bc9734ae22ac5296e28b399de9f278e984d Mon Sep 17 00:00:00 2001 From: Jonathan Carroll Date: Sun, 9 Sep 2018 17:01:08 -0700 Subject: [PATCH 2/2] documentation fix --- R/upset.R | 6 +++--- man/upset.Rd | 15 ++++++++++----- 2 files changed, 13 insertions(+), 8 deletions(-) diff --git a/R/upset.R b/R/upset.R index 46bedf3..3695b6f 100644 --- a/R/upset.R +++ b/R/upset.R @@ -99,9 +99,9 @@ #' upset(movies, nsets = 7, nintersects = 30, mb.ratio = c(0.5, 0.5), #' order.by = c("freq", "degree"), decreasing = c(TRUE,FALSE)) #' -# upset(movies, nsets = 7, nintersects = 30, mb.ratio = c(0.5, 0.5), -# order.by = c("freq", "degree"), decreasing = c(TRUE,FALSE), -# title = "Movies", title.pos = c(x = 0.1, y = 0.95)) +#' upset(movies, nsets = 7, nintersects = 30, mb.ratio = c(0.5, 0.5), +#' order.by = c("freq", "degree"), decreasing = c(TRUE,FALSE), +#' title = "Movies", title.pos = c(x = 0.1, y = 0.95)) #' #' upset(movies, sets = c("Drama", "Comedy", "Action", "Thriller", "Western", "Documentary"), #' queries = list(list(query = intersects, params = list("Drama", "Action")), diff --git a/man/upset.Rd b/man/upset.Rd index cfb758c..1a5165d 100644 --- a/man/upset.Rd +++ b/man/upset.Rd @@ -5,7 +5,8 @@ \title{UpSetR Plot} \usage{ upset(data, nsets = 5, nintersects = 40, sets = NULL, keep.order = F, - set.metadata = NULL, intersections = NULL, title = "", title.pos = c(x = 0.65, y = 0.95), matrix.color = "gray23", + set.metadata = NULL, title = "", title.pos = c(x = 0.65, y = 0.95), + intersections = NULL, matrix.color = "gray23", main.bar.color = "gray23", mainbar.y.label = "Intersection Size", mainbar.y.max = NULL, sets.bar.color = "gray23", sets.x.label = "Set Size", point.size = 2.2, line.size = 0.7, @@ -17,8 +18,8 @@ upset(data, nsets = 5, nintersects = 40, sets = NULL, keep.order = F, matrix.dot.alpha = 0.5, empty.intersections = NULL, color.pal = 1, boxplot.summary = NULL, attribute.plots = NULL, scale.intersections = "identity", scale.sets = "identity", - text.scale = 1, set_size.angles = 0, set_size.show = FALSE, set_size.numbers_size = NULL, - set_size.scale_max = NULL) + text.scale = 1, set_size.angles = 0, set_size.show = FALSE, + set_size.numbers_size = NULL, set_size.scale_max = NULL) } \arguments{ \item{data}{Data set} @@ -31,7 +32,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,6 +166,10 @@ attributeplots <- list(gridrows = 55, upset(movies, nsets = 7, nintersects = 30, mb.ratio = c(0.5, 0.5), order.by = c("freq", "degree"), decreasing = c(TRUE,FALSE)) +upset(movies, nsets = 7, nintersects = 30, mb.ratio = c(0.5, 0.5), + order.by = c("freq", "degree"), decreasing = c(TRUE,FALSE), + title = "Movies", title.pos = c(x = 0.1, y = 0.95)) + upset(movies, sets = c("Drama", "Comedy", "Action", "Thriller", "Western", "Documentary"), queries = list(list(query = intersects, params = list("Drama", "Action")), list(query = between, params = list(1970, 1980), color = "red", active = TRUE))) @@ -174,7 +179,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