I really like the look of ggplot2 and often use them to display raster data (for example, time- ggplot2 for time-varying precipitation fields is very useful).
However, I am still wondering if it is easy to output continuous raster values into discrete cells and assign each box one color , which is shown in the legend (as many GIS systems).
I tried with the arguments guide = "legend" and breaks the scale_fill_gradient parameter. However, they only affect the legend on the side of the chart, but the plotted values are still continuous.
library(ggplot2) data <- data.frame(x=rep(seq(1:10),times = 10), y=rep(seq(1:10),each = 10), value = runif(100,-10,10)) ggplot(data = data, aes(x=x,y=y)) + geom_raster(aes(fill = value)) + coord_equal() + scale_fill_gradient2(low = "darkred", mid = "white", high = "midnightblue", guide = "legend", breaks = c(-8,-4,0,4,8))
My question basically is how to discretize data built in ggplot so that the graph reader can draw quantitative conclusions about the values represented by colors.
Secondly, how can I use a diverging color palette (similar to scale_fill_gradient2 ) that is centered around zero or another specific value?
source share