diff --git a/DESCRIPTION b/DESCRIPTION index aa6ae2c..8fc45d0 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -26,4 +26,4 @@ LazyData: true VignetteBuilder: knitr Suggests: knitr -RoxygenNote: 5.0.1 +RoxygenNote: 6.0.1 diff --git a/R/MainBar.R b/R/MainBar.R index be72d63..afdbab5 100644 --- a/R/MainBar.R +++ b/R/MainBar.R @@ -61,11 +61,11 @@ 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 - + if(is.null(attribute_plots) == FALSE){ bottom_margin <- (-1)*0.45 } @@ -101,8 +101,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) == T){ - 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"){ @@ -117,8 +117,11 @@ 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) + + scale_y_continuous(trans = scale_intersections, labels = labels_arg) + ylim(0, ymax) + geom_bar(stat = "identity", width = 0.6, fill = Main_bar_data$color) @@ -128,7 +131,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")){ 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)) @@ -186,6 +189,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") diff --git a/R/SizeBar.R b/R/SizeBar.R index 9e96023..1213e1b 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,16 +32,16 @@ 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){ -# if(ratios[1] < 0.4){ -# m <- (-0.05) -# } -# else if((ratios[1] > 0.4) & (ratios[1] < 0.46)){ -# m <- (-0.03) -# } -# else{ -# m <- 0 -# } +Make_size_plot <- function(Set_size_data, sbar_color, ratios, ylabel, scale_sets, text_scale, set_size_angle, sets.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(length(text_scale) > 1 && length(text_scale) <= 6){ x_axis_title_scale <- text_scale[3] @@ -83,17 +83,19 @@ 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(scale_sets == "log10"){ - 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"){ - 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{ - Size_plot <- (Size_plot + scale_y_continuous(trans = "reverse")) + Size_plot <- (Size_plot + scale_y_continuous(trans = "reverse", labels = labels_arg)) } Size_plot <- ggplot_gtable(ggplot_build(Size_plot)) return(Size_plot) } - diff --git a/R/upset.R b/R/upset.R index 2212308..cdb0435 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 #' @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 #' Hadley Wickhams apply function. To further analyze the data contained in the intersections, the user may select additional attribute plots @@ -119,7 +121,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 ){ + scale.sets = "identity", text.scale = 1, set_size.angles = 0, sets.comma = F, mainbar.comma = F){ startend <-FindStartEnd(data) first.col <- startend[1] @@ -154,7 +156,7 @@ upset <- function(data, nsets = 5, nintersects = 40, sets = NULL, keep.order = F New_data <- Wanted(data, Sets_to_remove) Num_of_set <- Number_of_sets(Set_names) if(keep.order == F){ - Set_names <- order_sets(New_data, Set_names) + Set_names <- order_sets(New_data, Set_names) } All_Freqs <- Counter(New_data, Num_of_set, first.col, Set_names, nintersects, main.bar.color, order.by, group.by, cutoff, empty.intersections, decreasing) @@ -244,20 +246,20 @@ upset <- function(data, nsets = 5, nintersects = 40, sets = NULL, keep.order = F set.metadata <- output[[2]] if(is.null(ShadingData) == FALSE){ - shade.alpha <- unique(ShadingData$alpha) + shade.alpha <- unique(ShadingData$alpha) } } if(is.null(ShadingData) == TRUE){ - ShadingData <- MakeShading(Matrix_layout, shade.color) + 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) + Sizes <- Make_size_plot(Set_sizes, sets.bar.color, mb.ratio, sets.x.label, scale.sets, text.scale, set_size.angles, 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, legend, query.legend, BoxPlots, Set_names, set.metadata, set.metadata.plots) -} \ No newline at end of file +} 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..08fd7ec 100644 --- a/man/upset.Rd +++ b/man/upset.Rd @@ -17,7 +17,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) + text.scale = 1, set_size.angles = 0, sets.comma = F, + mainbar.comma = F) } \arguments{ \item{data}{Data set} @@ -108,6 +109,10 @@ a custom ggplots and the x and y aesthetics for the function. ncols is the numbe 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{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. @@ -176,4 +181,3 @@ Original UpSet Website: \url{http://vcg.github.io/upset/about/} UpSetR github for additional examples: \url{http://github.com/hms-dbmi/UpSetR} } -