Skip to content

Commit

Permalink
Fix size bar number positioning and give leverage over set size scale…
Browse files Browse the repository at this point in the history
… maximum
  • Loading branch information
Jake Conway authored and Jake Conway committed Aug 8, 2018
1 parent 129e60f commit 572be88
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 26 deletions.
36 changes: 29 additions & 7 deletions R/SizeBar.R
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ 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){
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){
# if(ratios[1] < 0.4){
# m <- (-0.05)
# }
Expand Down Expand Up @@ -62,16 +63,22 @@ Make_size_plot <- function(Set_size_data, sbar_color, ratios, ylabel, scale_sets
}
}

if(!is.null(set_size.number_size)) {
num.size <- (set_size.number_size/ggplot2:::.pt)*x_axis_tick_label_scale
} else {
num.size <- (7/ggplot2:::.pt)*x_axis_tick_label_scale
}

Size_plot <- (ggplot(data = Set_size_data, aes_string(x ="x", y = "y"))
+ geom_bar(stat = "identity",colour = sbar_color, width = 0.4,
fill = sbar_color, position = "identity")
+ scale_x_continuous(limits = c(0.5, (nrow(Set_size_data)+0.5)),
+ scale_x_continuous(limits = c(0.5, (nrow(Set_size_data) + 0.5)),
breaks = c(0, max(Set_size_data)),
expand = c(0,0))
+ theme(panel.background = element_rect(fill = "white"),
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, angle = set_size_angle,
axis.text.x = element_text(size = 7*x_axis_tick_label_scale,
vjust = 1, hjust = 0.5),
axis.line = element_line(colour = "gray0"),
axis.line.y = element_blank(),
Expand All @@ -84,17 +91,32 @@ Make_size_plot <- function(Set_size_data, sbar_color, ratios, ylabel, scale_sets
+ coord_flip())

if(set_size.show == TRUE){
Size_plot <- (Size_plot + geom_text(aes(label=y,vjust=0.5,hjust=0.1),size=(7/ggplot2:::.pt)*x_axis_tick_label_scale))
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"){
Size_plot <- (Size_plot + scale_y_continuous(trans = log10_reverse_trans()))
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()))
} else {
Size_plot <- (Size_plot + scale_y_continuous(trans = log10_reverse_trans()))
}
}
else if (scale_sets == "log2"){
Size_plot <- (Size_plot + scale_y_continuous(trans = log2_reverse_trans()))
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()))
} else {
Size_plot <- (Size_plot + scale_y_continuous(trans = log2_reverse_trans()))
}
}
else{
Size_plot <- (Size_plot + scale_y_continuous(trans = "reverse"))
if(!is.null(set_size.scale_max)) {
Size_plot <- (Size_plot + scale_y_continuous(limits = c(set_size.scale_max, 0),
trans = "reverse"))
} else {
Size_plot <- (Size_plot + scale_y_continuous(trans = "reverse"))
}
}

Size_plot <- ggplot_gtable(ggplot_build(Size_plot))
Expand Down
10 changes: 7 additions & 3 deletions R/upset.R
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@
#' 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.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
#' @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 Wickham's apply function. To further analyze the data contained in the intersections, the user may select additional attribute plots
Expand Down Expand Up @@ -120,7 +122,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 ){
scale.sets = "identity", text.scale = 1, set_size.angles = 0 , set_size.show = FALSE, set_size.numbers_size = NULL, set_size.scale_max = NULL){

startend <-FindStartEnd(data)
first.col <- startend[1]
Expand Down Expand Up @@ -257,8 +259,9 @@ upset <- function(data, nsets = 5, nintersects = 40, sets = NULL, keep.order = F
mainbar.y.max, scale.intersections, text.scale, attribute.plots))
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.show,
set_size.scale_max, set_size.numbers_size)

# 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)
Expand Down Expand Up @@ -287,6 +290,7 @@ upset <- function(data, nsets = 5, nintersects = 40, sets = NULL, keep.order = F
set.metadata.plots = set.metadata.plots)
)
}

#' @export
print.upset <- function(x, newpage = TRUE) {
Make_base_plot(
Expand Down
38 changes: 22 additions & 16 deletions man/upset.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 572be88

Please sign in to comment.