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

Fix color control of plotScoreHeatmap when 'normalize=TRUE' #259

Merged
merged 6 commits into from
Jan 5, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
20 changes: 11 additions & 9 deletions R/plotScoreHeatmap.R
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,16 @@
#' Contents should be the reference-labels in the order you would like them to appear, from top-to-bottom.
#' For combined results, include labels for all plots in a single vector and labels relevant to each plot will be extracted.
#' @param na.color String specifying the color for non-calculated scores of combined \code{results}.
#' @param color NA or a vector of colors passed to the \code{\link[pheatmap]{pheatmap}} input of the same name.
#' When left as NA, SingleR defaults are used.
#' @param breaks,legend_breaks,legend_labels NA or vectors of values or labels passed to the \code{\link[pheatmap]{pheatmap}} input of the same name.
#' By default SingleR uses these inputs: \itemize{
#' \item when \code{normalize=FALSE}), to ensure use of evenly diverging color legend extents and labels.
#' \item when \code{normalize=TRUE), to relabel only legend extents as "Lower" and "Higher" as actual normalized values have little meaning.
#' \item always when NA values exist in the targeted scores, even if you set them, to display the \code{na.color} in the legend.
#' }
#' This will always be displayed in the legend if any \code{NA} values are present in the scores.
#' @param color Character vector of colors passed to \code{\link[pheatmap]{pheatmap}}.
#' If \code{NA} and \code{normalize=TRUE}, the viridis color scheme is used by default;
#' while if \code{normalize=FALSE}, a default red-blue color scheme is chosen that should be symmetric around zero (see \code{breaks}).
#' @param breaks Numeric vector to map scores to colors, see the argument of the same name in \code{\link[pheatmap]{pheatmap}}.
#' If \code{NA}, this defaults to a sequence from 0 to 1 when \code{normalize=TRUE},
#' or a sequence from -T to T where T is the largest absolute score when \code{normalize=FALSE}.
#' @param legend_breaks,legend_labels Arguments passed to \code{\link[pheatmap]{pheatmap}} to label the legend.
#' If \code{NA}, only the legend extremes are labelled by default;
#' and when \code{normalize=TRUE}, the legend extremes are only labelled as \dQuote{Lower} and \dQuote{Higher}, as actual normalized values have little meaning.
#' @param annotation_col,cluster_cols,show_colnames,silent,...
#' Additional parameters for heatmap control passed to \code{\link[pheatmap]{pheatmap}}.
#' @param grid.vars A named list of extra variables to pass to \code{\link[gridExtra]{grid.arrange}},
Expand Down Expand Up @@ -368,7 +370,7 @@ plotScoreHeatmap <- function(results, cells.use = NULL, labels.use = NULL,
abs.max <- max(abs(range(scores, na.rm = TRUE)))
breaks.len <- length(args$color)+1
default_breaks <- seq(-abs.max, abs.max, length.out = breaks.len)
default_legend_breaks <- c(-abs.max, abs.max, length.out = 3)
default_legend_breaks <- c(-abs.max, abs.max)
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oops, your bugfix here went the opposite way of what I'd have intended to do. I would have left the length.out and swapped back to the original seq() had I caught it....

Ultimately though, 🤷, new version just removes a middle label in the legend, which was always at zero. Now only the ends of the legend will be labeled but that's totally fine!

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ha, I was wondering which way it should go. Ended up just flipping a coin in my head.

default_legend_labels <- round(default_legend_breaks, 3)
}
args$breaks <- default_if_NA(breaks, default_breaks)
Expand Down
22 changes: 19 additions & 3 deletions man/plotScoreHeatmap.Rd

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

Loading