I have a dataset which has a handful of outliers that I'm plotting as a raster in ggplot. Unmodified color schemes tend to highlight these outliers at the expense of showing the distribution of most of the data. Setting limits helps, but values above the specified limits are lost. Is there a way to make values above limits plot at the end of the color ramp?
Here's an example from the faithful dataset. It's not a perfect analogy to my data, since there's no outliers causing problems, but it shows my question.
ggplot(faithfuld, aes(waiting, eruptions)) +
geom_raster(aes(fill = density))+
scale_fill_gradientn(colours =
c("red", "orange", "yellow", "green","blue","purple","white"))
Let's say I want focus less on the higher values. Perhaps there a better way to do this rather than setting limits? With limits, I loose the data above the maximum (0.03, here).
ggplot(faithfuld, aes(waiting, eruptions)) +
geom_raster(aes(fill = density))+
scale_fill_gradientn(limits = c(0,.03),
colours = c("red","orange", "yellow", "green","blue",
"purple","white"))
Ideally, I'd like to plot this like in GIS, where values above my limit would be set to the max value of the color ramp. I could always hack the data to for it display this, but I'm hoping there's a more elegant solution within ggplot.