Skip to content

Instantly share code, notes, and snippets.

@dwinter
Created February 16, 2013 21:27
Show Gist options
  • Save dwinter/4968807 to your computer and use it in GitHub Desktop.
Save dwinter/4968807 to your computer and use it in GitHub Desktop.
library(ggplot2)
df0 <- data.frame(x=rnorm(100), y=rnorm(100), grp=factor(rep(letters[1:2], each=50)))
p <- ggplot(df0, aes(x,y, colour=grp, alpha=y))
p + geom_point()
library(RColorBrewer)
cuts <- with(df0, tapply(y, grp, cut, 3, labels=F))
df0$col <- c(brewer.pal(n=3, "Blues")[cuts$a], brewer.pal(n=3, "Reds")[cuts$b])
p2 <- ggplot(df0, aes(x,y,colour=col))
p2 + geom_point() +scale_colour_identity()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment