diff --git a/R/Boxplot.R b/R/Boxplot.R index 3939e25..6445859 100644 --- a/R/Boxplot.R +++ b/R/Boxplot.R @@ -33,13 +33,29 @@ IntersectionBoxPlot <- function(data1, data2, start_col, names){ } ## Generate boxplot summary plots -BoxPlotsPlot <- function(bdat, att, att_color){ +BoxPlotsPlot <- function(bdat, att, att_color, boxpl_kw = NULL){ yaxis <- as.character(att) col <- match(att, colnames(bdat)) colnames(bdat)[col] <- "attribute" upper_xlim <- as.numeric((max(bdat$x) + 1)) plot_lims <- as.numeric(0:upper_xlim) bdat$x <- as.factor(bdat$x) + # if boxpl_kw is not null, read the width and colour/color value of this named + # list, and use in boxplot + if(!is.null(boxpl_kw)){ + if("width" %in% names(boxpl_kw)){ + width <- boxpl_kw$width + } else { + width <- 1 + } + if("color" %in% names(boxpl_kw)){ + border_color <- boxpl_kw$color + } else if ("colour" %in% names(boxpl_kw)) { + border_color <- boxpl_kw$colour + } else { + border_color <- "gray80" + } + } boxplots <- ggplotGrob(ggplot() + theme_bw() +ylab(yaxis) + scale_x_discrete(limits = plot_lims, expand = c(0,0)) @@ -52,6 +68,7 @@ BoxPlotsPlot <- function(bdat, att, att_color){ panel.grid.major = element_blank(), axis.title.x = element_blank()) + geom_boxplot(data = bdat, aes_string(x="x", y="attribute"), - fill = att_color, colour = "gray80")) + fill = att_color, colour = border_color, + width = width)) return(boxplots) } \ No newline at end of file diff --git a/R/upset.R b/R/upset.R index 20c09c8..6964201 100644 --- a/R/upset.R +++ b/R/upset.R @@ -57,6 +57,7 @@ #' @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 +#' @param boxpl_kw Named list of parameters to be passed to the boxplot function. Options include width and color/colour. If not specified, defaults (width = 1 and colour = "grey80") are used. #' @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 @@ -124,7 +125,8 @@ upset <- function(data, nsets = 5, nintersects = 40, sets = NULL, keep.order = F decreasing = c(T, F), show.numbers = "yes", number.angles = 0, number.colors=NULL, 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.show = FALSE, set_size.numbers_size = NULL, set_size.scale_max = NULL, + boxpl_kw = NULL){ startend <-FindStartEnd(data) first.col <- startend[1] @@ -193,7 +195,7 @@ upset <- function(data, nsets = 5, nintersects = 40, sets = NULL, keep.order = F BoxData <- IntersectionBoxPlot(All_Freqs, New_data, first.col, Set_names) BoxPlots <- list() for(i in seq_along(boxplot.summary)){ - BoxPlots[[i]] <- BoxPlotsPlot(BoxData, boxplot.summary[i], att.color) + BoxPlots[[i]] <- BoxPlotsPlot(BoxData, boxplot.summary[i], att.color, boxpl_kw) } }