Created
August 30, 2012 15:59
-
-
Save dsparks/3531680 to your computer and use it in GitHub Desktop.
Transformed color scale with nice guide in ggplot2
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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