Skip to content

Commit 572be88

Browse files
Jake ConwayJake Conway
authored andcommitted
Fix size bar number positioning and give leverage over set size scale maximum
1 parent 129e60f commit 572be88

File tree

3 files changed

+58
-26
lines changed

3 files changed

+58
-26
lines changed

R/SizeBar.R

Lines changed: 29 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,8 @@ log2_reverse_trans <- function(){
3232
}
3333

3434
## Generate set size plot
35-
Make_size_plot <- function(Set_size_data, sbar_color, ratios, ylabel, scale_sets, text_scale, set_size_angle,set_size.show){
35+
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,
36+
set_size.number_size){
3637
# if(ratios[1] < 0.4){
3738
# m <- (-0.05)
3839
# }
@@ -62,16 +63,22 @@ Make_size_plot <- function(Set_size_data, sbar_color, ratios, ylabel, scale_sets
6263
}
6364
}
6465

66+
if(!is.null(set_size.number_size)) {
67+
num.size <- (set_size.number_size/ggplot2:::.pt)*x_axis_tick_label_scale
68+
} else {
69+
num.size <- (7/ggplot2:::.pt)*x_axis_tick_label_scale
70+
}
71+
6572
Size_plot <- (ggplot(data = Set_size_data, aes_string(x ="x", y = "y"))
6673
+ geom_bar(stat = "identity",colour = sbar_color, width = 0.4,
6774
fill = sbar_color, position = "identity")
68-
+ scale_x_continuous(limits = c(0.5, (nrow(Set_size_data)+0.5)),
75+
+ scale_x_continuous(limits = c(0.5, (nrow(Set_size_data) + 0.5)),
6976
breaks = c(0, max(Set_size_data)),
7077
expand = c(0,0))
7178
+ theme(panel.background = element_rect(fill = "white"),
7279
plot.margin=unit(c(-0.11,-1.3,0.5,0.5), "lines"),
7380
axis.title.x = element_text(size = 8.3*x_axis_title_scale),
74-
axis.text.x = element_text(size = 7*x_axis_tick_label_scale, angle = set_size_angle,
81+
axis.text.x = element_text(size = 7*x_axis_tick_label_scale,
7582
vjust = 1, hjust = 0.5),
7683
axis.line = element_line(colour = "gray0"),
7784
axis.line.y = element_blank(),
@@ -84,17 +91,32 @@ Make_size_plot <- function(Set_size_data, sbar_color, ratios, ylabel, scale_sets
8491
+ coord_flip())
8592

8693
if(set_size.show == TRUE){
87-
Size_plot <- (Size_plot + geom_text(aes(label=y,vjust=0.5,hjust=0.1),size=(7/ggplot2:::.pt)*x_axis_tick_label_scale))
94+
Size_plot <- (Size_plot + geom_text(aes(label=y,vjust=0.5,hjust=1.2, angle = set_size_angle), size=num.size))
8895
}
8996

9097
if(scale_sets == "log10"){
91-
Size_plot <- (Size_plot + scale_y_continuous(trans = log10_reverse_trans()))
98+
if(!is.null(set_size.scale_max)) {
99+
Size_plot <- (Size_plot + scale_y_continuous(limits = c(set_size.scale_max, 0),
100+
trans = log10_reverse_trans()))
101+
} else {
102+
Size_plot <- (Size_plot + scale_y_continuous(trans = log10_reverse_trans()))
103+
}
92104
}
93105
else if (scale_sets == "log2"){
94-
Size_plot <- (Size_plot + scale_y_continuous(trans = log2_reverse_trans()))
106+
if(!is.null(set_size.scale_max)) {
107+
Size_plot <- (Size_plot + scale_y_continuous(limits = c(set_size.scale_max, 0),
108+
trans = log2_reverse_trans()))
109+
} else {
110+
Size_plot <- (Size_plot + scale_y_continuous(trans = log2_reverse_trans()))
111+
}
95112
}
96113
else{
97-
Size_plot <- (Size_plot + scale_y_continuous(trans = "reverse"))
114+
if(!is.null(set_size.scale_max)) {
115+
Size_plot <- (Size_plot + scale_y_continuous(limits = c(set_size.scale_max, 0),
116+
trans = "reverse"))
117+
} else {
118+
Size_plot <- (Size_plot + scale_y_continuous(trans = "reverse"))
119+
}
98120
}
99121

100122
Size_plot <- ggplot_gtable(ggplot_build(Size_plot))

R/upset.R

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,8 @@
5353
#' in the following format: c(intersection size title, intersection size tick labels, set size title, set size tick labels, set names, numbers above bars)
5454
#' @param set_size.angles Numeric, angle to rotate the set size plot x-axis text
5555
#' @param set_size.show Logical, display the set sizes on the set size bar chart
56+
#' @param set_size.numbers_size If set_size.show is TRUE, adjust the size of the numbers
57+
#' @param set_size.scale_max Increase the maximum of set size scale
5658
#' @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}.
5759
#' UpSet also allows for visualization of queries on intersections and elements, along with custom queries queries implemented using
5860
#' Hadley Wickham's apply function. To further analyze the data contained in the intersections, the user may select additional attribute plots
@@ -120,7 +122,7 @@ upset <- function(data, nsets = 5, nintersects = 40, sets = NULL, keep.order = F
120122
decreasing = c(T, F), show.numbers = "yes", number.angles = 0, group.by = "degree",cutoff = NULL,
121123
queries = NULL, query.legend = "none", shade.color = "gray88", shade.alpha = 0.25, matrix.dot.alpha =0.5,
122124
empty.intersections = NULL, color.pal = 1, boxplot.summary = NULL, attribute.plots = NULL, scale.intersections = "identity",
123-
scale.sets = "identity", text.scale = 1, set_size.angles = 0 , set_size.show = FALSE ){
125+
scale.sets = "identity", text.scale = 1, set_size.angles = 0 , set_size.show = FALSE, set_size.numbers_size = NULL, set_size.scale_max = NULL){
124126

125127
startend <-FindStartEnd(data)
126128
first.col <- startend[1]
@@ -257,8 +259,9 @@ upset <- function(data, nsets = 5, nintersects = 40, sets = NULL, keep.order = F
257259
mainbar.y.max, scale.intersections, text.scale, attribute.plots))
258260
Matrix <- Make_matrix_plot(Matrix_layout, Set_sizes, All_Freqs, point.size, line.size,
259261
text.scale, labels, ShadingData, shade.alpha)
260-
Sizes <- Make_size_plot(Set_sizes, sets.bar.color, mb.ratio, sets.x.label, scale.sets, text.scale, set_size.angles,set_size.show)
261-
262+
Sizes <- Make_size_plot(Set_sizes, sets.bar.color, mb.ratio, sets.x.label, scale.sets, text.scale, set_size.angles,set_size.show,
263+
set_size.scale_max, set_size.numbers_size)
264+
262265
# Make_base_plot(Main_bar, Matrix, Sizes, labels, mb.ratio, att.x, att.y, New_data,
263266
# expression, att.pos, first.col, att.color, AllQueryData, attribute.plots,
264267
# legend, query.legend, BoxPlots, Set_names, set.metadata, set.metadata.plots)
@@ -287,6 +290,7 @@ upset <- function(data, nsets = 5, nintersects = 40, sets = NULL, keep.order = F
287290
set.metadata.plots = set.metadata.plots)
288291
)
289292
}
293+
290294
#' @export
291295
print.upset <- function(x, newpage = TRUE) {
292296
Make_base_plot(

man/upset.Rd

Lines changed: 22 additions & 16 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)