Box plot showing mean as a line
问题 Is it possible to create a boxplot that shows both mean and median as a line with the standard boxplot function of R ? My current solution displays the mean as a cross: set.seed(1234) values <- runif(10,0,1) boxplot(values) points(mean(values),col="red",pch=4,lwd = 4) 回答1: For the sake of completeness, you could also overplot: set.seed(753) df <- data.frame(y=rt(100, 4), x=gl(5, 20)) bx.p <- boxplot(y~x, df) bx.p$stats[3, ] <- unclass(with(df, by(y, x, FUN = mean))) bxp(bx.p, add=T, boxfill=