Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add label comma options #69

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,4 @@ LazyData: true
VignetteBuilder: knitr
Suggests:
knitr
RoxygenNote: 5.0.1
RoxygenNote: 6.0.1
20 changes: 13 additions & 7 deletions R/MainBar.R
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down Expand Up @@ -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"){
Expand All @@ -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)
Expand All @@ -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))
Expand Down Expand Up @@ -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")
Expand Down
32 changes: 17 additions & 15 deletions R/SizeBar.R
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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]
Expand Down Expand Up @@ -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)
}

16 changes: 9 additions & 7 deletions R/upset.R
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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]
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)

}
}
1 change: 0 additions & 1 deletion man/elements.Rd

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

1 change: 0 additions & 1 deletion man/fromExpression.Rd

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

1 change: 0 additions & 1 deletion man/fromList.Rd

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

1 change: 0 additions & 1 deletion man/histogram.Rd

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

1 change: 0 additions & 1 deletion man/intersects.Rd

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

1 change: 0 additions & 1 deletion man/scatter_plot.Rd

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

8 changes: 6 additions & 2 deletions man/upset.Rd

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