Skip to content

Instantly share code, notes, and snippets.

@jimjh
Created April 25, 2013 01:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jimjh/5456801 to your computer and use it in GitHub Desktop.
Save jimjh/5456801 to your computer and use it in GitHub Desktop.
An easier way to build custom color gradients with R.
color.grad <- function(input, bins=10) {
colors <- c('#FFFFFF', heat.colors(bins-1)) # white for 0/NA
input[is.na(input)] <- 0 # replace NA with 0
colors[cut(input, bins, labels=F)] # break up into bins, project colors
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment