1library(ggplot2)
2# Basic histogram
3ggplot(df, aes(x=weight)) + geom_histogram()
4# Change the width of bins
5ggplot(df, aes(x=weight)) +
6 geom_histogram(binwidth=1)
7# Change colors
8p<-ggplot(df, aes(x=weight)) +
9 geom_histogram(color="black", fill="white")
10p
1# Add mean line
2p+ geom_vline(aes(xintercept=mean(weight)),
3 color="blue", linetype="dashed", size=1)
4# Histogram with density plot
5ggplot(df, aes(x=weight)) +
6 geom_histogram(aes(y=..density..), colour="black", fill="white")+
7 geom_density(alpha=.2, fill="#FF6666")