2
votes

I have this code:

require(reshape2)
library(ggplot2)
library(RColorBrewer)

df <- read.csv("https://dl.dropboxusercontent.com/u/73950/moduVSmnc.csv")
breaks1 <- seq(1.85,2.5,by=0.05)

gg <- aggregate(mnc~cut(apl,breaks=breaks1,
labels=format(breaks1[-1],nsmall=2))+modu,df,mean)

colnames(gg)<- c("apl","modu","mnc")
gg$modu <- as.factor(gg$modu)
library(ggplot2)
library(RColorBrewer)
ggplot(gg) + 
  geom_tile(aes(x=modu,y=apl,fill=mnc))+
  scale_fill_gradientn(colours=rev(brewer.pal(10,"Spectral"))) +
  coord_fixed()

which produces:

enter image description here

Now, I'd like this plot to show all values under 40 as dark blue (as if value was 0), and then start smoothly moving to green, yellow, orange, red and dark red (brewer's spectral colour scale) until maximum value.

How to achieve this with ggplot2?

1

1 Answers

3
votes

I am not sure if I understood your question correctly. Why not remap all mnc<40 to 40 and recolor?

gg$mnc2<-gg$mnc
gg$mnc2[gg$mnc2<40]<-40


ggplot(gg) + 
  geom_tile(aes(x=modu,y=apl,fill=mnc2))+
  scale_fill_gradientn(colours=rev(brewer.pal(11,"Spectral"))) +
  coord_fixed()

enter image description here