Open LTLA opened 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)
Discuss (3 marks).