Last active
August 29, 2015 14:02
-
-
Save muschellij2/b3b803df7a4cd165dbd4 to your computer and use it in GitHub Desktop.
Quick updown histogram
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) | |
df = data.frame(x = rnorm(100), x2 = rnorm(100, mean=2)) | |
g = ggplot(df, aes(x)) + geom_histogram( aes(x = x, y = ..density..), fill="blue") + | |
geom_histogram( aes(x = x2, y = -..density..), fill= "green") | |
print(g) | |
## using base | |
h1 = hist(df$x) | |
h2 = hist(df$x2) | |
h2$counts = - h2$counts | |
hmax = max(h1$counts) | |
hmin = min(h2$counts) | |
X = c(h1$breaks, h2$breaks) | |
xmax = max(X) | |
xmin = min(X) | |
plot(h1, ylim=c(hmin, hmax), col="green", xlim=c(xmin, xmax)) | |
lines(h2, col="blue") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment