alanocallaghan / scater

Clone of the Bioconductor repository for the scater package.
https://bioconductor.org/packages/devel/bioc/html/scater.html
94 stars 38 forks source link

Do different settings for symmetric= and center= in plotHeatmap ever make sense? #134

Open LTLA opened 3 years ago

LTLA commented 3 years ago

Discuss (3 marks).

alanocallaghan commented 3 years ago

symmetric=TRUE and center=FALSE doesn't ever make sense to me.

For the converse I think you can come up with contrived cases where it ends up with a marginally less bad colour scale but in general no, I don't think it makes sense. It's enough of an edge case that it probably doesn't need to be handled by default. Better to have vaguely sensible behaviour in 90% of cases than to try to catch everything


library("ggplot2")
library("RColorBrewer")
library("viridis")
#> Loading required package: viridisLite
x <- rnorm(100)
x[1:20] <- abs(x[1:20])
x[80] <- -5

plot_colors <- function(x, symmetric = FALSE) {
    x <- x - mean(x)
    ggplot() +
        aes(1:length(x), x, color = x) +
        geom_point() +
        scale_color_gradientn(
            colors=if (symmetric) brewer.pal(9, "RdYlBu") else viridis(9),
            limits = if (symmetric) c(-max(abs(x)), max(abs(x))) else range(x)
        )
}
plot_colors(x, symmetric=TRUE)

plot_colors(x, symmetric=FALSE)