I\'m faced with the following problem: a few extreme values are dominating the colorscale of my geom_raster
plot. An example is probably more clear (note that t
Seems that ggplot (0.9.2.1) and scales (0.2.2) bring all you need (for your original m
):
library(scales)
qn = quantile(m$fill, c(0.01, 0.99), na.rm = TRUE)
qn01 <- rescale(c(qn, range(m$fill)))
ggplot(m, aes(x = x, y = y, fill = fill)) +
geom_raster() +
scale_fill_gradientn (
colours = colorRampPalette(c("darkblue", "white", "darkred"))(20),
values = c(0, seq(qn01[1], qn01[2], length.out = 18), 1)) +
theme(legend.key.height = unit (4.5, "lines"))