How do I add the mean value to a histogram in R?

Viewed 72244

I would like to plot a histogram with mean (average) value on it (e.g. we could mark it with a blue and bold line).

I tried to do it using plot command, but even if I set the parameter add=TRUE it didn't work.

4 Answers

If you have data frames with more columns using of ggplot2 package is my preferred option:

ggplot (data, aes (x = colname)) + geom_vline(xintercept=mean(data$colname), color="red")

Colname is column in your data.frame for which you would like to plot the histogram and mean.

Related