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

Added support for tibbles and commas #139

Open
wants to merge 16 commits 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: 6.1.0
RoxygenNote: 6.1.1
4 changes: 2 additions & 2 deletions R/Helper.funcs.R
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
38 changes: 25 additions & 13 deletions R/MainBar.R
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,10 @@ 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, intersection.size.comma){
bottom_margin <- (-1)*0.65

if(is.null(attribute_plots) == FALSE){
bottom_margin <- (-1)*0.45
}
Expand Down Expand Up @@ -99,9 +99,9 @@ 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){
ten_perc <- ((max(Main_bar_data$freq)) * 0.1)
ymax <- max(Main_bar_data$freq) + ten_perc
if(is.null(ymax)){
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 @@ -115,21 +115,33 @@ 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)
+ 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")){
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 = 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 = 0.5, hjust = -0.1,
angle = number_angles, colour = Main_bar_data$color))
}

}
bInterDat <- NULL
pInterDat <- NULL
Expand Down
61 changes: 40 additions & 21 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,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,
set_size.number_size){
# 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, 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(length(text_scale) > 1 && length(text_scale) <= 6){
x_axis_title_scale <- text_scale[3]
Expand Down Expand Up @@ -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),
Expand All @@ -90,32 +94,47 @@ 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))
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"){
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(limits = c(max(Set_size_data) + 0.1*max(Set_size_data), 0),
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(limits = c(max(Set_size_data) + 0.1*max(Set_size_data), 0),
trans = "reverse",
labels = labels_arg))
}
}

Expand Down
16 changes: 11 additions & 5 deletions R/upset.R
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,14 @@
#' @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".
#' @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
Expand Down Expand Up @@ -122,7 +127,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_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)
first.col <- startend[1]
Expand Down Expand Up @@ -256,11 +262,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, 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,
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_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,
# expression, att.pos, first.col, att.color, AllQueryData, attribute.plots,
Expand Down
18 changes: 15 additions & 3 deletions man/upset.Rd

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