-
Notifications
You must be signed in to change notification settings - Fork 14
Fix fill parameter handling in plotHistogram #214
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
Open
0xMuluh
wants to merge
5
commits into
devel
Choose a base branch
from
fill
base: devel
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
6c0f715
Fix fill parameter handling in plotHistogram
0xMuluh 64a1bcb
Merge branch 'devel' into fill
TuomasBorman 1443d00
Merge branch 'devel' into fill
0xMuluh b364b14
Merge branch 'devel' into fill
0xMuluh 45e30ed
Merge branch 'devel' into fill
0xMuluh File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -103,6 +103,7 @@ setMethod("plotHistogram", signature = c(x = "SummarizedExperiment"), | |
| x = x, assay.type = assay.type, features = features, | ||
| row.var = row.var, col.var = col.var) | ||
| args <- c(args, list(...)) | ||
| args[["fill"]] <- NULL # avoid partial matching to fill.by | ||
| temp <- do.call(.check_input_for_histogram, args) | ||
| # Get the data from the object | ||
| args[["mode"]] <- "histogram" | ||
|
|
@@ -127,6 +128,7 @@ setMethod("plotBarplot", signature = c(x = "SummarizedExperiment"), | |
| x = x, assay.type = assay.type, features = features, | ||
| row.var = row.var, col.var = col.var) | ||
| args <- c(args, list(...)) | ||
| args[["fill"]] <- NULL # avoid partial matching to fill.by | ||
| temp <- do.call(.check_input_for_histogram, args) | ||
| # Get the data from the object | ||
| args[["mode"]] <- "barplot" | ||
|
|
@@ -303,41 +305,15 @@ setMethod("plotBarplot", signature = c(x = "SummarizedExperiment"), | |
| position = ifelse( | ||
| !is.null(attributes(df)[["fill.by"]]), "dodge2", "identity"), | ||
| ...){ | ||
| # To disable "no visible binding for global variable" message in cmdcheck | ||
| value <- facet_by <- NULL | ||
| # Check layout | ||
| supported_layouts <- c("histogram", "density") | ||
| if( !(.is_a_string(layout) && all(layout %in% supported_layouts) ) ){ | ||
| stop("'layout' must be from the following options: '", | ||
| paste0(supported_layouts, collapse = "', '"), "'", call. = FALSE) | ||
| } | ||
| # Initialize a plot | ||
| p <- ggplot(df, aes( | ||
| x = value, | ||
| fill = if(!is.null(attributes(df)[["fill.by"]])) | ||
| .data[[attributes(df)[["fill.by"]]]] else fill | ||
| )) | ||
| # Either create histogram or density | ||
| if( layout == "density" ){ | ||
| p <- p + geom_density(color = color, alpha = alpha, ...) | ||
| } else{ | ||
| p <- p + geom_histogram( | ||
| color = color, alpha = alpha, position = position, ...) | ||
| } | ||
| # Apply facetting | ||
| if( length(attributes(df)[["facet.by"]]) > 0L ){ | ||
| p <- p + facet_grid(attributes(df)[["facet.by"]], scales = scales) | ||
| } | ||
| # Adjust theme | ||
| p <- p + theme_classic() | ||
| # Adjust titles | ||
| p <- p + labs(x = attributes(df)[["x"]]) | ||
| if( !is.null(attributes(df)[["fill.by"]]) ){ | ||
| p <- p + labs(fill = attributes(df)[["fill.by"]]) | ||
| } else{ | ||
| p <- p + guides(fill = "none") | ||
| } | ||
| return(p) | ||
| geom_fun <- switch(layout, histogram = geom_histogram, density = geom_density) | ||
| .plot_hist_bar(df, geom_fun, layout == "histogram", color, fill, | ||
| alpha, scales, position, ...) | ||
| } | ||
|
|
||
| # This function gets data.frame and creates a plot. | ||
|
|
@@ -347,16 +323,31 @@ setMethod("plotBarplot", signature = c(x = "SummarizedExperiment"), | |
| position = ifelse( | ||
| !is.null(attributes(df)[["fill.by"]]), "dodge2", "identity"), | ||
| ...){ | ||
| .plot_hist_bar(df, geom_bar, TRUE, color, fill, alpha, scales, | ||
| position, ...) | ||
| } | ||
|
Comment on lines
+326
to
+328
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. End every function with return() |
||
|
|
||
| # This function creates a histogram or bar plot from a data.frame. | ||
| .plot_hist_bar <- function(df, geom_fun, use_position, color, fill, | ||
| alpha, scales, position, ...){ | ||
| # To disable "no visible binding for global variable" message in cmdcheck | ||
| value <- facet_by <- NULL | ||
| fill_by <- attributes(df)[["fill.by"]] | ||
| mapping <- aes(x = value) | ||
| if (!is.null(fill_by)) { | ||
| mapping <- aes(x = value, fill = .data[[fill_by]]) | ||
| } | ||
|
Comment on lines
+337
to
+339
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Use the same formatting as in rest of the package |
||
| # Initialize a plot | ||
| p <- ggplot(df, aes( | ||
| x = value, | ||
| fill = if(!is.null(attributes(df)[["fill.by"]])) | ||
| .data[[attributes(df)[["fill.by"]]]] else fill | ||
| )) | ||
| # Either create barplot | ||
| p <- p + geom_bar(color = color, alpha = alpha, position = position, ...) | ||
| p <- ggplot(df, mapping) | ||
| layer_args <- list(color = color, alpha = alpha, ...) | ||
| if (is.null(fill_by)) { | ||
| layer_args$fill <- fill | ||
| } | ||
| if (use_position) { | ||
| layer_args$position <- position | ||
| } | ||
| # Either create histogram or density or barplot layer | ||
| p <- p + do.call(geom_fun, layer_args) | ||
| # Apply facetting | ||
| if( length(attributes(df)[["facet.by"]]) > 0L ){ | ||
| p <- p + facet_grid(attributes(df)[["facet.by"]], scales = scales) | ||
|
|
@@ -365,8 +356,8 @@ setMethod("plotBarplot", signature = c(x = "SummarizedExperiment"), | |
| p <- p + theme_classic() | ||
| # Adjust titles | ||
| p <- p + labs(x = attributes(df)[["x"]]) | ||
| if( !is.null(attributes(df)[["fill.by"]]) ){ | ||
| p <- p + labs(fill = attributes(df)[["fill.by"]]) | ||
| if( !is.null(fill_by) ){ | ||
| p <- p + labs(fill = fill_by) | ||
| } else{ | ||
| p <- p + guides(fill = "none") | ||
| } | ||
|
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
use_position is redundant. You can overwrite
position <- NULLiflayout == "density"