-
-
Save juliasilge/1808b7c15e3805bdd9c43367d6ff977c to your computer and use it in GitHub Desktop.
Overlapping Density Plots
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(dplyr) | |
library(tidyr) | |
library(ggplot2) | |
library(gridExtra) | |
df = data_frame(a = rnorm(100, mean=1), b=rnorm(100, mean=2), c=rnorm(100, mean=0)) %>% | |
gather("var", "value", a,b,c) | |
ggplot(df, aes(x=value)) + | |
geom_density(fill="black", col="white", lwd=1) + | |
facet_grid(var~1, switch="y") + | |
theme(strip.text.x=element_blank(), panel.background=element_blank(), | |
panel.margin.y=unit(-3, "cm"), panel.grid=element_blank(), | |
axis.ticks.y=element_blank(), axis.text.y=element_blank()) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This didn't work for me when I tried it. First it wanted
panel.margin.y
to bepanel.spacing.y
and then it didn't like thefacet grid
.