Skip to content

Instantly share code, notes, and snippets.

@noamross
Last active July 27, 2016 04:55
Show Gist options
  • Save noamross/fecc0619e35843fa979276c7de326bd3 to your computer and use it in GitHub Desktop.
Save noamross/fecc0619e35843fa979276c7de326bd3 to your computer and use it in GitHub Desktop.
Overlapping Density Plots
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())
@noamross
Copy link
Author

noamross commented Jul 13, 2016

The result:
screen shot 2016-07-13 at 9 28 21 am

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment