Skip to content

Instantly share code, notes, and snippets.

@t-student
Last active October 14, 2015 05:57
Show Gist options
  • Save t-student/ddb8966d2a6fd6a6b2d7 to your computer and use it in GitHub Desktop.
Save t-student/ddb8966d2a6fd6a6b2d7 to your computer and use it in GitHub Desktop.
# Density plot in R using ggplot
library(ggplot2)
p <- ggplot(data = df, aes(x = response))
p <- p + geom_histogram(aes(y=..density..), binwidth = 0.3, fill="grey", colour="black")
p <- p + geom_line(stat="density", size = 1)
p <- p + geom_rug()
p <- p + xlab("x")
p <- p + ylab("Probability density")
p <- p + theme_bw()
p <- p + theme(legend.title=element_blank())
p <- p + theme(legend.position='bottom')
p <- p + theme(text = element_text(size=10))
print(p)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment