Is it possible to plot a histogram in R and having the mean, median and mode automatically marked on the X-axis (the arrows don't need to be angled, or even arrows, as long as these 3 values are clearly marked)
edit: the plot is indeed from SPSS, but for my purposes, hist(airmiles)
from the default datasets package would do.
edit 2: abline indeed does the job, but my preference is still labeled arrows, and the answers that show up as potential duplicates do not show how to do that.
edit 3: pretty happy with these results -- many thanks people:
hist(cars$horse, main="Horsepower distribution", xlab="Horsepower", breaks=40)
marked.labels = vector()
marked.colors = vector()
mark <- function(v, l, c) {
abline(v = v, col = c)
mtext(expression({}%up%{}), side = 1, line = 0, at = v, col=c)
marked.labels <<- c(marked.labels, paste(l, '=', v))
marked.colors <<- c(marked.colors, c)
}
mark(mean(cars$horse, na.rm=TRUE), 'mean', 'red')
mark(median(cars$horse, na.rm=TRUE), 'median', 'blue')
mark(getmode(cars$horse), 'mode', 'darkgreen')
legend("topright", legend=marked.labels, col=marked.colors, lty=1, cex=0.8)