From 5c778acd8eb31727db45dc6741ca29ccf02c0d57 Mon Sep 17 00:00:00 2001 From: Mario Date: Mon, 12 Nov 2018 18:07:46 -0600 Subject: [PATCH 01/16] Edited MainBar.R for commas --- R/MainBar.R | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/R/MainBar.R b/R/MainBar.R index 978c119..4a6d242 100644 --- a/R/MainBar.R +++ b/R/MainBar.R @@ -61,7 +61,7 @@ Counter <- function(data, num_sets, start_col, name_of_sets, nintersections, mba ## Generate main bar plot Make_main_bar <- function(Main_bar_data, Q, show_num, ratios, customQ, number_angles, - ebar, ylabel, ymax, scale_intersections, text_scale, attribute_plots){ + ebar, ylabel, ymax, scale_intersections, text_scale, attribute_plots, mainbar.comma){ bottom_margin <- (-1)*0.65 @@ -115,8 +115,10 @@ Make_main_bar <- function(Main_bar_data, Q, show_num, ratios, customQ, number_an Main_bar_data$freq <- round(log10(Main_bar_data$freq), 2) ymax <- log10(ymax) } + labels_arg <- waiver() + if(mainbar.comma) labels_arg <- scales::comma Main_bar_plot <- (ggplot(data = Main_bar_data, aes_string(x = "x", y = "freq")) - + scale_y_continuous(trans = scale_intersections) + + scale_y_continuous(trans = scale_intersections, labels = labels_arg) + ylim(0, ymax) + geom_bar(stat = "identity", width = 0.6, fill = Main_bar_data$color) @@ -183,6 +185,9 @@ Make_main_bar <- function(Main_bar_data, Q, show_num, ratios, customQ, number_an position = position_jitter(width = 0.2, height = 0.2), colour = pElemDat$color, size = 2, shape = 17)) } + if(mainbar.comma){ + Main_bar_plot <- (Main_bar_plot + scale_y_continuous(labels = scales::comma)) + } Main_bar_plot <- (Main_bar_plot + geom_vline(xintercept = 0, color = "gray0") From 1f6bef1d906d6d83672cef9eb5a0fe02d40daa37 Mon Sep 17 00:00:00 2001 From: Mario Date: Mon, 12 Nov 2018 18:16:40 -0600 Subject: [PATCH 02/16] Edited SizeBar.R for commas --- R/SizeBar.R | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/R/SizeBar.R b/R/SizeBar.R index 62c8a5b..f9751fa 100644 --- a/R/SizeBar.R +++ b/R/SizeBar.R @@ -33,7 +33,7 @@ log2_reverse_trans <- function(){ ## Generate set size plot Make_size_plot <- function(Set_size_data, sbar_color, ratios, ylabel, scale_sets, text_scale, set_size_angle, set_size.show, set_size.scale_max, - set_size.number_size){ + set_size.number_size, sets.comma){ # if(ratios[1] < 0.4){ # m <- (-0.05) # } @@ -90,6 +90,9 @@ Make_size_plot <- function(Set_size_data, sbar_color, ratios, ylabel, scale_sets + xlab(NULL) + ylab(ylabel) + coord_flip()) + labels_arg <- waiver() + if(sets.comma) labels_arg <- scales::comma + if(set_size.show == TRUE){ Size_plot <- (Size_plot + geom_text(aes(label=y,vjust=0.5,hjust=1.2, angle = set_size_angle), size=num.size)) } @@ -97,25 +100,31 @@ Make_size_plot <- function(Set_size_data, sbar_color, ratios, ylabel, scale_sets if(scale_sets == "log10"){ if(!is.null(set_size.scale_max)) { Size_plot <- (Size_plot + scale_y_continuous(limits = c(set_size.scale_max, 0), - trans = log10_reverse_trans())) + trans = log10_reverse_trans(), + labels = labels_arg)) } else { - Size_plot <- (Size_plot + scale_y_continuous(trans = log10_reverse_trans())) + Size_plot <- (Size_plot + scale_y_continuous(trans = log10_reverse_trans(), + labels = labels_arg)) } } else if (scale_sets == "log2"){ if(!is.null(set_size.scale_max)) { Size_plot <- (Size_plot + scale_y_continuous(limits = c(set_size.scale_max, 0), - trans = log2_reverse_trans())) + trans = log2_reverse_trans(), + labels = labels_arg)) } else { - Size_plot <- (Size_plot + scale_y_continuous(trans = log2_reverse_trans())) + Size_plot <- (Size_plot + scale_y_continuous(trans = log2_reverse_trans(), + labels = labels_arg)) } } else{ if(!is.null(set_size.scale_max)) { Size_plot <- (Size_plot + scale_y_continuous(limits = c(set_size.scale_max, 0), - trans = "reverse")) + trans = "reverse", + labels = labels_arg)) } else { - Size_plot <- (Size_plot + scale_y_continuous(trans = "reverse")) + Size_plot <- (Size_plot + scale_y_continuous(trans = "reverse", + labels = labels_arg)) } } From 54e84f9a14425ac130c928ad7e475355e54d7ac6 Mon Sep 17 00:00:00 2001 From: Mario Date: Mon, 12 Nov 2018 18:27:24 -0600 Subject: [PATCH 03/16] Edited upset.R for commas --- R/upset.R | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/R/upset.R b/R/upset.R index 40cba8d..963a95b 100644 --- a/R/upset.R +++ b/R/upset.R @@ -52,6 +52,8 @@ #' @param text.scale Numeric, value to scale the text sizes, applies to all axis labels, tick labels, and numbers above bar plot. Can be a universal scale, or a vector containing individual scales #' in the following format: c(intersection size title, intersection size tick labels, set size title, set size tick labels, set names, numbers above bars) #' @param set_size.angles Numeric, angle to rotate the set size plot x-axis text +#' @param sets.comma Logical, format numeric labels with commas +#' @param mainbar.comma Logical, format numeric labels with commas #' @param set_size.show Logical, display the set sizes on the set size bar chart #' @param set_size.numbers_size If set_size.show is TRUE, adjust the size of the numbers #' @param set_size.scale_max Increase the maximum of set size scale @@ -122,7 +124,8 @@ upset <- function(data, nsets = 5, nintersects = 40, sets = NULL, keep.order = F decreasing = c(T, F), show.numbers = "yes", number.angles = 0, group.by = "degree",cutoff = NULL, queries = NULL, query.legend = "none", shade.color = "gray88", shade.alpha = 0.25, 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){ + scale.sets = "identity", text.scale = 1, set_size.angles = 0 , set_size.show = FALSE, set_size.numbers_size = NULL, set_size.scale_max = NULL, + sets.comma = F, mainbar.comma = F){ startend <-FindStartEnd(data) first.col <- startend[1] @@ -256,11 +259,11 @@ upset <- function(data, nsets = 5, nintersects = 40, sets = NULL, keep.order = F ShadingData <- MakeShading(Matrix_layout, shade.color) } Main_bar <- suppressMessages(Make_main_bar(All_Freqs, Bar_Q, show.numbers, mb.ratio, customQBar, number.angles, EBar_data, mainbar.y.label, - mainbar.y.max, scale.intersections, text.scale, attribute.plots)) + mainbar.y.max, scale.intersections, text.scale, attribute.plots, mainbar.comma)) Matrix <- Make_matrix_plot(Matrix_layout, Set_sizes, All_Freqs, point.size, line.size, text.scale, labels, ShadingData, shade.alpha) - Sizes <- Make_size_plot(Set_sizes, sets.bar.color, mb.ratio, sets.x.label, scale.sets, text.scale, set_size.angles,set_size.show, - set_size.scale_max, set_size.numbers_size) + Sizes <- Make_size_plot(Set_sizes, sets.bar.color, mb.ratio, sets.x.label, scale.sets, text.scale, set_size.angles, set_size.show, + set_size.scale_max, set_size.numbers_size, sets.comma) # Make_base_plot(Main_bar, Matrix, Sizes, labels, mb.ratio, att.x, att.y, New_data, # expression, att.pos, first.col, att.color, AllQueryData, attribute.plots, From 5b0084af3066c98852cee095ddcd501ffa6c04b8 Mon Sep 17 00:00:00 2001 From: Mario Date: Mon, 12 Nov 2018 18:40:15 -0600 Subject: [PATCH 04/16] Call 'roxygenize' to update documentation --- DESCRIPTION | 2 +- man/upset.Rd | 6 +++++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index 22a3b42..7be50e3 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -26,4 +26,4 @@ LazyData: true VignetteBuilder: knitr Suggests: knitr -RoxygenNote: 6.1.0 +RoxygenNote: 6.1.1 diff --git a/man/upset.Rd b/man/upset.Rd index 34b8598..7dd54af 100644 --- a/man/upset.Rd +++ b/man/upset.Rd @@ -19,7 +19,7 @@ upset(data, nsets = 5, nintersects = 40, sets = 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) + set_size.scale_max = NULL, sets.comma = F, mainbar.comma = F) } \arguments{ \item{data}{Data set} @@ -116,6 +116,10 @@ in the following format: c(intersection size title, intersection size tick label \item{set_size.numbers_size}{If set_size.show is TRUE, adjust the size of the numbers} \item{set_size.scale_max}{Increase the maximum of set size scale} + +\item{sets.comma}{Logical, format numeric labels with commas} + +\item{mainbar.comma}{Logical, format numeric labels with commas} } \description{ Visualization of set intersections using novel UpSet matrix design. From e8b383738a3c6089250d0ecfb56e01b9d275995b Mon Sep 17 00:00:00 2001 From: Mario Date: Mon, 12 Nov 2018 19:07:54 -0600 Subject: [PATCH 05/16] Fix to work with tibbles --- R/Helper.funcs.R | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/R/Helper.funcs.R b/R/Helper.funcs.R index af9f8bc..492d18d 100644 --- a/R/Helper.funcs.R +++ b/R/Helper.funcs.R @@ -2,7 +2,7 @@ FindStartEnd <- function(data){ startend <- c() for(i in 1:ncol(data)){ - column <- data[, i] + column <- data[[i]] column <- (levels(factor(column))) if((column[1] == "0") && (column[2] == "1" && (length(column) == 2))){ startend[1] <- i @@ -21,7 +21,7 @@ FindStartEnd <- function(data){ } } for(i in ncol(data):1){ - column <- data[ ,i] + column <- data[[i]] column <- (levels(factor(column))) if((column[1] == "0") && (column[2] == "1") && (length(column) == 2)){ startend[2] <- i From 933f7536237b4b32107a8fb269fabc58786c1036 Mon Sep 17 00:00:00 2001 From: Mario Date: Tue, 13 Nov 2018 12:56:07 -0600 Subject: [PATCH 06/16] Update to use commas in top of intersection size --- R/MainBar.R | 12 +++++++++--- R/upset.R | 5 +++-- man/upset.Rd | 5 ++++- 3 files changed, 16 insertions(+), 6 deletions(-) diff --git a/R/MainBar.R b/R/MainBar.R index 4a6d242..08cdd2b 100644 --- a/R/MainBar.R +++ b/R/MainBar.R @@ -61,7 +61,7 @@ Counter <- function(data, num_sets, start_col, name_of_sets, nintersections, mba ## Generate main bar plot Make_main_bar <- function(Main_bar_data, Q, show_num, ratios, customQ, number_angles, - ebar, ylabel, ymax, scale_intersections, text_scale, attribute_plots, mainbar.comma){ + ebar, ylabel, ymax, scale_intersections, text_scale, attribute_plots, mainbar.comma, intersection.size.comma){ bottom_margin <- (-1)*0.65 @@ -130,8 +130,14 @@ Make_main_bar <- function(Main_bar_data, Q, show_num, ratios, customQ, number_an axis.title.y = element_text(vjust = -0.8, size = 8.3*y_axis_title_scale), axis.text.y = element_text(vjust=0.3, size=7*y_axis_tick_label_scale))) if((show_num == "yes") || (show_num == "Yes")){ - Main_bar_plot <- (Main_bar_plot + geom_text(aes_string(label = "freq"), size = 2.2*intersection_size_number_scale, vjust = -1, - angle = number_angles, colour = Main_bar_data$color)) + if(!intersection.size.comma){ + Main_bar_plot <- (Main_bar_plot + geom_text(aes_string(label = "freq"), size = 2.2*intersection_size_number_scale, vjust = -1, + angle = number_angles, colour = Main_bar_data$color)) + } else{ + Main_bar_plot <- (Main_bar_plot + geom_text(aes(label = scales::comma(freq)), size = 2.2*intersection_size_number_scale, vjust = -1, + angle = number_angles, colour = Main_bar_data$color)) + } + } bInterDat <- NULL pInterDat <- NULL diff --git a/R/upset.R b/R/upset.R index 963a95b..374c387 100644 --- a/R/upset.R +++ b/R/upset.R @@ -54,6 +54,7 @@ #' @param set_size.angles Numeric, angle to rotate the set size plot x-axis text #' @param sets.comma Logical, format numeric labels with commas #' @param mainbar.comma Logical, format numeric labels with commas +#' @param intersection.size.comma Logical, format numeric labels with commas. Ignored if @param show.numbers is not "yes". #' @param set_size.show Logical, display the set sizes on the set size bar chart #' @param set_size.numbers_size If set_size.show is TRUE, adjust the size of the numbers #' @param set_size.scale_max Increase the maximum of set size scale @@ -125,7 +126,7 @@ upset <- function(data, nsets = 5, nintersects = 40, sets = NULL, keep.order = F queries = NULL, query.legend = "none", shade.color = "gray88", shade.alpha = 0.25, 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, - sets.comma = F, mainbar.comma = F){ + sets.comma = F, mainbar.comma = F, intersection.size.comma = F){ startend <-FindStartEnd(data) first.col <- startend[1] @@ -259,7 +260,7 @@ upset <- function(data, nsets = 5, nintersects = 40, sets = NULL, keep.order = F ShadingData <- MakeShading(Matrix_layout, shade.color) } Main_bar <- suppressMessages(Make_main_bar(All_Freqs, Bar_Q, show.numbers, mb.ratio, customQBar, number.angles, EBar_data, mainbar.y.label, - mainbar.y.max, scale.intersections, text.scale, attribute.plots, mainbar.comma)) + mainbar.y.max, scale.intersections, text.scale, attribute.plots, mainbar.comma, intersection.size.comma)) Matrix <- Make_matrix_plot(Matrix_layout, Set_sizes, All_Freqs, point.size, line.size, text.scale, labels, ShadingData, shade.alpha) Sizes <- Make_size_plot(Set_sizes, sets.bar.color, mb.ratio, sets.x.label, scale.sets, text.scale, set_size.angles, set_size.show, diff --git a/man/upset.Rd b/man/upset.Rd index 7dd54af..dd5c456 100644 --- a/man/upset.Rd +++ b/man/upset.Rd @@ -19,7 +19,8 @@ upset(data, nsets = 5, nintersects = 40, sets = 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, sets.comma = F, mainbar.comma = F) + set_size.scale_max = NULL, sets.comma = F, mainbar.comma = F, + intersection.size.comma = F) } \arguments{ \item{data}{Data set} @@ -120,6 +121,8 @@ in the following format: c(intersection size title, intersection size tick label \item{sets.comma}{Logical, format numeric labels with commas} \item{mainbar.comma}{Logical, format numeric labels with commas} + +\item{intersection.size.comma}{Logical, format numeric labels with commas. Ignored if @param show.numbers is not "yes".} } \description{ Visualization of set intersections using novel UpSet matrix design. From e5c9d73a04cf79b3f6099fe0222039d9a5259e98 Mon Sep 17 00:00:00 2001 From: Mario Date: Tue, 13 Nov 2018 15:35:54 -0600 Subject: [PATCH 07/16] Update documentation for intersection.size.comma parameter --- R/upset.R | 2 +- man/upset.Rd | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/R/upset.R b/R/upset.R index 374c387..f0f13a3 100644 --- a/R/upset.R +++ b/R/upset.R @@ -54,7 +54,7 @@ #' @param set_size.angles Numeric, angle to rotate the set size plot x-axis text #' @param sets.comma Logical, format numeric labels with commas #' @param mainbar.comma Logical, format numeric labels with commas -#' @param intersection.size.comma Logical, format numeric labels with commas. Ignored if @param show.numbers is not "yes". +#' @param intersection.size.comma Logical, format numeric labels with commas. Ignored if `show.numbers` is not "yes". #' @param set_size.show Logical, display the set sizes on the set size bar chart #' @param set_size.numbers_size If set_size.show is TRUE, adjust the size of the numbers #' @param set_size.scale_max Increase the maximum of set size scale diff --git a/man/upset.Rd b/man/upset.Rd index dd5c456..9991c56 100644 --- a/man/upset.Rd +++ b/man/upset.Rd @@ -122,7 +122,7 @@ in the following format: c(intersection size title, intersection size tick label \item{mainbar.comma}{Logical, format numeric labels with commas} -\item{intersection.size.comma}{Logical, format numeric labels with commas. Ignored if @param show.numbers is not "yes".} +\item{intersection.size.comma}{Logical, format numeric labels with commas. Ignored if `show.numbers` is not "yes".} } \description{ Visualization of set intersections using novel UpSet matrix design. From f65d053a2655842cf55227dca1d9b82442b5a1f4 Mon Sep 17 00:00:00 2001 From: Mario Date: Wed, 14 Nov 2018 10:59:40 -0600 Subject: [PATCH 08/16] Add support for commas in set size bar plot --- R/SizeBar.R | 8 ++++++-- R/upset.R | 7 ++++--- man/upset.Rd | 6 ++++-- 3 files changed, 14 insertions(+), 7 deletions(-) diff --git a/R/SizeBar.R b/R/SizeBar.R index f9751fa..31d7c5f 100644 --- a/R/SizeBar.R +++ b/R/SizeBar.R @@ -33,7 +33,7 @@ log2_reverse_trans <- function(){ ## Generate set size plot Make_size_plot <- function(Set_size_data, sbar_color, ratios, ylabel, scale_sets, text_scale, set_size_angle, set_size.show, set_size.scale_max, - set_size.number_size, sets.comma){ + set_size.number_size, sets.comma, set_size.number_comma){ # if(ratios[1] < 0.4){ # m <- (-0.05) # } @@ -94,7 +94,11 @@ Make_size_plot <- function(Set_size_data, sbar_color, ratios, ylabel, scale_sets if(sets.comma) labels_arg <- scales::comma if(set_size.show == TRUE){ - Size_plot <- (Size_plot + geom_text(aes(label=y,vjust=0.5,hjust=1.2, angle = set_size_angle), size=num.size)) + if(set_size.number_comma){ + Size_plot <- (Size_plot + geom_text(aes(label = scales::comma(y), vjust=0.5,hjust=1.2, angle = set_size_angle), size=num.size)) + } else{ + Size_plot <- (Size_plot + geom_text(aes(label=y,vjust=0.5,hjust=1.2, angle = set_size_angle), size=num.size)) + } } if(scale_sets == "log10"){ diff --git a/R/upset.R b/R/upset.R index f0f13a3..b7f8b00 100644 --- a/R/upset.R +++ b/R/upset.R @@ -54,9 +54,10 @@ #' @param set_size.angles Numeric, angle to rotate the set size plot x-axis text #' @param sets.comma Logical, format numeric labels with commas #' @param mainbar.comma Logical, format numeric labels with commas -#' @param intersection.size.comma Logical, format numeric labels with commas. Ignored if `show.numbers` is not "yes". +#' @param intersection.size.comma Logical, format numeric labels with commas. Ignored if show.numbers is not "yes". #' @param set_size.show Logical, display the set sizes on the set size bar chart #' @param set_size.numbers_size If set_size.show is TRUE, adjust the size of the numbers +#' @param set_size.number_comma Logical, format numeric labels with commas. Ignored if set_size.show is FALSE. #' @param set_size.scale_max Increase the maximum of set size scale #' @details Visualization of set data in the layout described by Lex and Gehlenborg in \url{http://www.nature.com/nmeth/journal/v11/n8/abs/nmeth.3033.html}. #' UpSet also allows for visualization of queries on intersections and elements, along with custom queries queries implemented using @@ -126,7 +127,7 @@ upset <- function(data, nsets = 5, nintersects = 40, sets = NULL, keep.order = F queries = NULL, query.legend = "none", shade.color = "gray88", shade.alpha = 0.25, 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, - sets.comma = F, mainbar.comma = F, intersection.size.comma = F){ + sets.comma = F, mainbar.comma = F, intersection.size.comma = F, set_size.number_comma = F){ startend <-FindStartEnd(data) first.col <- startend[1] @@ -264,7 +265,7 @@ upset <- function(data, nsets = 5, nintersects = 40, sets = NULL, keep.order = F Matrix <- Make_matrix_plot(Matrix_layout, Set_sizes, All_Freqs, point.size, line.size, text.scale, labels, ShadingData, shade.alpha) Sizes <- Make_size_plot(Set_sizes, sets.bar.color, mb.ratio, sets.x.label, scale.sets, text.scale, set_size.angles, set_size.show, - set_size.scale_max, set_size.numbers_size, sets.comma) + set_size.scale_max, set_size.numbers_size, sets.comma, set_size.number_comma) # Make_base_plot(Main_bar, Matrix, Sizes, labels, mb.ratio, att.x, att.y, New_data, # expression, att.pos, first.col, att.color, AllQueryData, attribute.plots, diff --git a/man/upset.Rd b/man/upset.Rd index 9991c56..c8dc04f 100644 --- a/man/upset.Rd +++ b/man/upset.Rd @@ -20,7 +20,7 @@ upset(data, nsets = 5, nintersects = 40, sets = NULL, scale.sets = "identity", text.scale = 1, set_size.angles = 0, set_size.show = FALSE, set_size.numbers_size = NULL, set_size.scale_max = NULL, sets.comma = F, mainbar.comma = F, - intersection.size.comma = F) + intersection.size.comma = F, set_size.number_comma = F) } \arguments{ \item{data}{Data set} @@ -122,7 +122,9 @@ in the following format: c(intersection size title, intersection size tick label \item{mainbar.comma}{Logical, format numeric labels with commas} -\item{intersection.size.comma}{Logical, format numeric labels with commas. Ignored if `show.numbers` is not "yes".} +\item{intersection.size.comma}{Logical, format numeric labels with commas. Ignored if show.numbers is not "yes".} + +\item{set_size.number_comma}{Logical, format numeric labels with commas. Ignored if set_size.show is FALSE.} } \description{ Visualization of set intersections using novel UpSet matrix design. From a58699168f9377bb537315a71a7835a65437196d Mon Sep 17 00:00:00 2001 From: Mario Date: Tue, 27 Nov 2018 15:45:52 -0600 Subject: [PATCH 09/16] Parameter to change x axis angle in set size plot --- R/SizeBar.R | 30 +++++++++++++++++------------- R/upset.R | 7 ++++--- man/upset.Rd | 11 +++++++---- 3 files changed, 28 insertions(+), 20 deletions(-) diff --git a/R/SizeBar.R b/R/SizeBar.R index 31d7c5f..e44e310 100644 --- a/R/SizeBar.R +++ b/R/SizeBar.R @@ -6,7 +6,7 @@ FindSetFreqs <- function(data, start_col, num_sets, set_names, keep_order){ temp_data <- as.data.frame(colSums(temp_data)) colnames(temp_data) <- c("y") if(keep_order == FALSE){ - temp_data <- temp_data[order(temp_data$y, decreasing = T), ] + temp_data <- temp_data[order(temp_data$y, decreasing = T), ] } else{ temp_data <- temp_data$y @@ -32,17 +32,17 @@ log2_reverse_trans <- function(){ } ## Generate set size plot -Make_size_plot <- function(Set_size_data, sbar_color, ratios, ylabel, scale_sets, text_scale, set_size_angle, set_size.show, set_size.scale_max, +Make_size_plot <- function(Set_size_data, sbar_color, ratios, ylabel, scale_sets, text_scale, set_size_angle, set_size_x_axis.angles, set_size.show, set_size.scale_max, set_size.number_size, sets.comma, set_size.number_comma){ -# if(ratios[1] < 0.4){ -# m <- (-0.05) -# } -# else if((ratios[1] > 0.4) & (ratios[1] < 0.46)){ -# m <- (-0.03) -# } -# else{ -# m <- 0 -# } + # if(ratios[1] < 0.4){ + # m <- (-0.05) + # } + # else if((ratios[1] > 0.4) & (ratios[1] < 0.46)){ + # m <- (-0.03) + # } + # else{ + # m <- 0 + # } if(length(text_scale) > 1 && length(text_scale) <= 6){ x_axis_title_scale <- text_scale[3] @@ -79,7 +79,11 @@ Make_size_plot <- function(Set_size_data, sbar_color, ratios, ylabel, scale_sets plot.margin=unit(c(-0.11,-1.3,0.5,0.5), "lines"), axis.title.x = element_text(size = 8.3*x_axis_title_scale), axis.text.x = element_text(size = 7*x_axis_tick_label_scale, - vjust = 1, hjust = 0.5), + vjust = 1, + # hjust = 0.5, + hjust = 1, + angle = set_size_x_axis.angles + ), axis.line = element_line(colour = "gray0"), axis.line.y = element_blank(), axis.line.x = element_line(colour = "gray0", size = 0.3), @@ -100,7 +104,7 @@ Make_size_plot <- function(Set_size_data, sbar_color, ratios, ylabel, scale_sets Size_plot <- (Size_plot + geom_text(aes(label=y,vjust=0.5,hjust=1.2, angle = set_size_angle), size=num.size)) } } - + if(scale_sets == "log10"){ if(!is.null(set_size.scale_max)) { Size_plot <- (Size_plot + scale_y_continuous(limits = c(set_size.scale_max, 0), diff --git a/R/upset.R b/R/upset.R index b7f8b00..4fb2b30 100644 --- a/R/upset.R +++ b/R/upset.R @@ -51,7 +51,8 @@ #' @param scale.sets The scale to be used for the set sizes. Options: "identity", "log10", "log2" #' @param text.scale Numeric, value to scale the text sizes, applies to all axis labels, tick labels, and numbers above bar plot. Can be a universal scale, or a vector containing individual scales #' in the following format: c(intersection size title, intersection size tick labels, set size title, set size tick labels, set names, numbers above bars) -#' @param set_size.angles Numeric, angle to rotate the set size plot x-axis text +#' @param set_size.angles Numeric, angle to rotate the set size plot text +#' @param set_size_x_axis.angles Numeric, angle to rotate the set size plot x-axis text #' @param sets.comma Logical, format numeric labels with commas #' @param mainbar.comma Logical, format numeric labels with commas #' @param intersection.size.comma Logical, format numeric labels with commas. Ignored if show.numbers is not "yes". @@ -126,7 +127,7 @@ upset <- function(data, nsets = 5, nintersects = 40, sets = NULL, keep.order = F decreasing = c(T, F), show.numbers = "yes", number.angles = 0, group.by = "degree",cutoff = NULL, queries = NULL, query.legend = "none", shade.color = "gray88", shade.alpha = 0.25, 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, + scale.sets = "identity", text.scale = 1, set_size.angles = 0 , set_size_x_axis.angles = 0, set_size.show = FALSE, set_size.numbers_size = NULL, set_size.scale_max = NULL, sets.comma = F, mainbar.comma = F, intersection.size.comma = F, set_size.number_comma = F){ startend <-FindStartEnd(data) @@ -264,7 +265,7 @@ upset <- function(data, nsets = 5, nintersects = 40, sets = NULL, keep.order = F mainbar.y.max, scale.intersections, text.scale, attribute.plots, mainbar.comma, intersection.size.comma)) Matrix <- Make_matrix_plot(Matrix_layout, Set_sizes, All_Freqs, point.size, line.size, text.scale, labels, ShadingData, shade.alpha) - Sizes <- Make_size_plot(Set_sizes, sets.bar.color, mb.ratio, sets.x.label, scale.sets, text.scale, set_size.angles, set_size.show, + Sizes <- Make_size_plot(Set_sizes, sets.bar.color, mb.ratio, sets.x.label, scale.sets, text.scale, set_size.angles, set_size_x_axis.angles, set_size.show, set_size.scale_max, set_size.numbers_size, sets.comma, set_size.number_comma) # Make_base_plot(Main_bar, Matrix, Sizes, labels, mb.ratio, att.x, att.y, New_data, diff --git a/man/upset.Rd b/man/upset.Rd index c8dc04f..98edcdd 100644 --- a/man/upset.Rd +++ b/man/upset.Rd @@ -18,9 +18,10 @@ upset(data, nsets = 5, nintersects = 40, sets = NULL, 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, sets.comma = F, mainbar.comma = F, - intersection.size.comma = F, set_size.number_comma = F) + set_size_x_axis.angles = 0, set_size.show = FALSE, + set_size.numbers_size = NULL, set_size.scale_max = NULL, + sets.comma = F, mainbar.comma = F, intersection.size.comma = F, + set_size.number_comma = F) } \arguments{ \item{data}{Data set} @@ -110,7 +111,9 @@ a custom ggplot and the x and y aesthetics for the function. ncols is the number \item{text.scale}{Numeric, value to scale the text sizes, applies to all axis labels, tick labels, and numbers above bar plot. Can be a universal scale, or a vector containing individual scales in the following format: c(intersection size title, intersection size tick labels, set size title, set size tick labels, set names, numbers above bars)} -\item{set_size.angles}{Numeric, angle to rotate the set size plot x-axis text} +\item{set_size.angles}{Numeric, angle to rotate the set size plot text} + +\item{set_size_x_axis.angles}{Numeric, angle to rotate the set size plot x-axis text} \item{set_size.show}{Logical, display the set sizes on the set size bar chart} From 79bede6ca0f5d238d2b9f3c2a2a00691ae2d76fc Mon Sep 17 00:00:00 2001 From: Mario Date: Tue, 27 Nov 2018 16:23:31 -0600 Subject: [PATCH 10/16] Increase y axis limit in size plot so that text is completely shown --- R/SizeBar.R | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/R/SizeBar.R b/R/SizeBar.R index e44e310..196ad24 100644 --- a/R/SizeBar.R +++ b/R/SizeBar.R @@ -111,7 +111,8 @@ Make_size_plot <- function(Set_size_data, sbar_color, ratios, ylabel, scale_sets trans = log10_reverse_trans(), labels = labels_arg)) } else { - Size_plot <- (Size_plot + scale_y_continuous(trans = log10_reverse_trans(), + Size_plot <- (Size_plot + scale_y_continuous(limits = c(max(Set_size_data) + 0.1*max(Set_size_data), 0), + trans = log10_reverse_trans(), labels = labels_arg)) } } @@ -131,7 +132,8 @@ Make_size_plot <- function(Set_size_data, sbar_color, ratios, ylabel, scale_sets trans = "reverse", labels = labels_arg)) } else { - Size_plot <- (Size_plot + scale_y_continuous(trans = "reverse", + Size_plot <- (Size_plot + scale_y_continuous(limits = c(max(Set_size_data) + 0.1*max(Set_size_data), 0), + trans = "reverse", labels = labels_arg)) } } From 821c9986c10ad61456506f52f84f41731179b8a9 Mon Sep 17 00:00:00 2001 From: Mario Date: Tue, 27 Nov 2018 16:47:42 -0600 Subject: [PATCH 11/16] Fix hjust and vjust of main bar plot --- R/MainBar.R | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/R/MainBar.R b/R/MainBar.R index 08cdd2b..1604e0d 100644 --- a/R/MainBar.R +++ b/R/MainBar.R @@ -131,10 +131,12 @@ Make_main_bar <- function(Main_bar_data, Q, show_num, ratios, customQ, number_an size=7*y_axis_tick_label_scale))) if((show_num == "yes") || (show_num == "Yes")){ if(!intersection.size.comma){ - Main_bar_plot <- (Main_bar_plot + geom_text(aes_string(label = "freq"), size = 2.2*intersection_size_number_scale, vjust = -1, + Main_bar_plot <- (Main_bar_plot + geom_text(aes_string(label = "freq"), size = 2.2*intersection_size_number_scale, + vjust = 0.5, hjust = -0.1, angle = number_angles, colour = Main_bar_data$color)) } else{ - Main_bar_plot <- (Main_bar_plot + geom_text(aes(label = scales::comma(freq)), size = 2.2*intersection_size_number_scale, vjust = -1, + Main_bar_plot <- (Main_bar_plot + geom_text(aes(label = scales::comma(freq)), size = 2.2*intersection_size_number_scale, + vjust = 0.5, hjust = -0.1, angle = number_angles, colour = Main_bar_data$color)) } From c953dc91ff6958cef910c95858d5d59f46419b66 Mon Sep 17 00:00:00 2001 From: Mario Date: Tue, 27 Nov 2018 16:49:04 -0600 Subject: [PATCH 12/16] Remove weird boolean comparison --- R/MainBar.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/R/MainBar.R b/R/MainBar.R index 1604e0d..20c82e0 100644 --- a/R/MainBar.R +++ b/R/MainBar.R @@ -99,7 +99,7 @@ Make_main_bar <- function(Main_bar_data, Q, show_num, ratios, customQ, number_an else{elem_data <- NULL} #ten_perc creates appropriate space above highest bar so number doesnt get cut off - if(is.null(ymax) == T){ + if(is.null(ymax)){ ten_perc <- ((max(Main_bar_data$freq)) * 0.1) ymax <- max(Main_bar_data$freq) + ten_perc } From fb2ada50f8af2dba5286ed58e3218a82197c6f53 Mon Sep 17 00:00:00 2001 From: Mario Date: Tue, 27 Nov 2018 16:49:12 -0600 Subject: [PATCH 13/16] Fix indent --- R/MainBar.R | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/R/MainBar.R b/R/MainBar.R index 20c82e0..1919e03 100644 --- a/R/MainBar.R +++ b/R/MainBar.R @@ -62,9 +62,9 @@ Counter <- function(data, num_sets, start_col, name_of_sets, nintersections, mba ## Generate main bar plot Make_main_bar <- function(Main_bar_data, Q, show_num, ratios, customQ, number_angles, ebar, ylabel, ymax, scale_intersections, text_scale, attribute_plots, mainbar.comma, intersection.size.comma){ - + bottom_margin <- (-1)*0.65 - + if(is.null(attribute_plots) == FALSE){ bottom_margin <- (-1)*0.45 } @@ -100,8 +100,8 @@ Make_main_bar <- function(Main_bar_data, Q, show_num, ratios, customQ, number_an #ten_perc creates appropriate space above highest bar so number doesnt get cut off if(is.null(ymax)){ - ten_perc <- ((max(Main_bar_data$freq)) * 0.1) - ymax <- max(Main_bar_data$freq) + ten_perc + ten_perc <- ((max(Main_bar_data$freq)) * 0.1) + ymax <- max(Main_bar_data$freq) + ten_perc } if(ylabel == "Intersection Size" && scale_intersections != "identity"){ @@ -128,7 +128,7 @@ Make_main_bar <- function(Main_bar_data, Q, show_num, ratios, customQ, number_an + theme(panel.background = element_rect(fill = "white"), plot.margin = unit(c(0.5,0.5,bottom_margin,0.5), "lines"), panel.border = element_blank(), axis.title.y = element_text(vjust = -0.8, size = 8.3*y_axis_title_scale), axis.text.y = element_text(vjust=0.3, - size=7*y_axis_tick_label_scale))) + size=7*y_axis_tick_label_scale))) if((show_num == "yes") || (show_num == "Yes")){ if(!intersection.size.comma){ Main_bar_plot <- (Main_bar_plot + geom_text(aes_string(label = "freq"), size = 2.2*intersection_size_number_scale, From 4740f422c2d79e3fdb0a8411e28fba381c90a793 Mon Sep 17 00:00:00 2001 From: Mario Date: Tue, 27 Nov 2018 17:12:30 -0600 Subject: [PATCH 14/16] Fix scale with commas in main bar plot --- R/MainBar.R | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/R/MainBar.R b/R/MainBar.R index 1919e03..143b45d 100644 --- a/R/MainBar.R +++ b/R/MainBar.R @@ -118,17 +118,19 @@ Make_main_bar <- function(Main_bar_data, Q, show_num, ratios, customQ, number_an labels_arg <- waiver() if(mainbar.comma) labels_arg <- scales::comma Main_bar_plot <- (ggplot(data = Main_bar_data, aes_string(x = "x", y = "freq")) - + scale_y_continuous(trans = scale_intersections, labels = labels_arg) - + ylim(0, ymax) + + scale_y_continuous(trans = scale_intersections, labels = labels_arg, limits = c(0, ymax)) + geom_bar(stat = "identity", width = 0.6, fill = Main_bar_data$color) + scale_x_continuous(limits = c(0,(nrow(Main_bar_data)+1 )), expand = c(0,0), breaks = NULL) - + xlab(NULL) + ylab(ylabel) +labs(title = NULL) + + xlab(NULL) + ylab(ylabel) + labs(title = NULL) + theme(panel.background = element_rect(fill = "white"), plot.margin = unit(c(0.5,0.5,bottom_margin,0.5), "lines"), panel.border = element_blank(), - axis.title.y = element_text(vjust = -0.8, size = 8.3*y_axis_title_scale), axis.text.y = element_text(vjust=0.3, - size=7*y_axis_tick_label_scale))) + axis.title.y = element_text(vjust = -0.8, + size = 8.3*y_axis_title_scale), + axis.text.y = element_text(vjust=0.3,size=7*y_axis_tick_label_scale)) + + scale_y_continuous(trans = scale_intersections, labels = labels_arg, limits = c(0, ymax)) + ) if((show_num == "yes") || (show_num == "Yes")){ if(!intersection.size.comma){ Main_bar_plot <- (Main_bar_plot + geom_text(aes_string(label = "freq"), size = 2.2*intersection_size_number_scale, @@ -193,9 +195,6 @@ Make_main_bar <- function(Main_bar_data, Q, show_num, ratios, customQ, number_an position = position_jitter(width = 0.2, height = 0.2), colour = pElemDat$color, size = 2, shape = 17)) } - if(mainbar.comma){ - Main_bar_plot <- (Main_bar_plot + scale_y_continuous(labels = scales::comma)) - } Main_bar_plot <- (Main_bar_plot + geom_vline(xintercept = 0, color = "gray0") From 4779a3e9c90822a69b9105f007dd7ac79d772963 Mon Sep 17 00:00:00 2001 From: Mario Date: Mon, 10 Dec 2018 16:53:49 -0600 Subject: [PATCH 15/16] Update project name --- UpSetr.Rproj => UpSetr2.Rproj | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename UpSetr.Rproj => UpSetr2.Rproj (100%) diff --git a/UpSetr.Rproj b/UpSetr2.Rproj similarity index 100% rename from UpSetr.Rproj rename to UpSetr2.Rproj From 75e744603298c30411187aed5a0c10b94e5fe3b6 Mon Sep 17 00:00:00 2001 From: Mario Date: Mon, 10 Dec 2018 16:58:15 -0600 Subject: [PATCH 16/16] Revert "Update project name" This reverts commit 4779a3e9c90822a69b9105f007dd7ac79d772963. --- UpSetr2.Rproj => UpSetr.Rproj | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename UpSetr2.Rproj => UpSetr.Rproj (100%) diff --git a/UpSetr2.Rproj b/UpSetr.Rproj similarity index 100% rename from UpSetr2.Rproj rename to UpSetr.Rproj