Skip to content

Instantly share code, notes, and snippets.

# 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())