Created
October 21, 2013 18:55
-
-
Save mattsigal/7089000 to your computer and use it in GitHub Desktop.
Simple example of transforming data/scale/coordinate system in ggplot2.
This file contains 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) | |
# Sample diamonds dataframe: | |
didat <- diamonds[sample(nrow(diamonds), 1000), ] | |
# Original data: | |
ggplot(didat, aes(x = depth, y = price)) + geom_point() | |
# Transform data: | |
ggplot(didat, aes(x = log10(depth), y = log10(price))) + geom_point() | |
# Transform scales (same plot visually as transform data, but scales go wonky): | |
ggplot(didat, aes(x = depth, y = price)) + geom_point() + | |
scale_x_log10() + scale_y_log10() | |
# Transform coordinate system: | |
ggplot(didat, aes(x = depth, y = price)) + geom_point() + | |
coord_trans(x = "log10", y = "log10") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Visual summary provided at http://rpubs.com/mattsigal/ggtransforms