Skip to content

Instantly share code, notes, and snippets.

@dsparks
Created August 30, 2012 15:59
Show Gist options
  • Save dsparks/3531680 to your computer and use it in GitHub Desktop.
Save dsparks/3531680 to your computer and use it in GitHub Desktop.
Transformed color scale with nice guide in ggplot2
library(ggplot2)
library(scales)
# Generate data
myData <- data.frame(x = rnorm(1000),
y = rnorm(1000))
myData$z <- with(myData, x * y)
# Make an untransformed plot
badVersion <- ggplot(myData,
aes(x = x, y = y, colour = z))
badVersion <- badVersion + geom_point()
print(badVersion)
# Make a custom transformation
norm_trans <- function(){
trans_new('norm', function(x) pnorm(x), function(x) qnorm(x))
}
# Update plot with transformed color scale
badVersion + scale_colour_continuous(trans = 'norm'))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment