Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
diverging color schemes for negative and positive numbers in R
library(RColorBrewer)
colPos<-colorRampPalette(brewer.pal(9, "YlGn")[3:9])(100)
colNeg<-colorRampPalette(brewer.pal(9, "OrRd")[3:9])(100)
foo <- function(diff, bin) {
if(diff>=0) colPos[bin] else colNeg[bin]
}
mat$diff <- mat$x-mat$y
mat$bin <- cut(log10(abs(mat$diff)+1),100, labels=seq(1,100))
mat$col <- mapply(foo, mat$diff, mat$bin)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.