[R] regression line on boxplots

Bernd Weiss bernd.weiss at uni-koeln.de
Fri Apr 1 17:45:03 CEST 2011


Am 01.04.2011 11:24, schrieb Yan Jiao:
> Dear R users,
>
> I'm trying to add a regression line on my boxplots (something
> like:boxplot(c(1:3),c(4:6),c(5:8))) But I can't see it. Please help
> !!! It's not a April fool's joke!!!

Your sample data does not make any sense (at least to me). I would do it 
as follows:

set.seed(8)
df <- data.frame(y = rnorm(100), x = factor(rep(1:4)))
boxplot(y ~ x, data = df)
regline <- lm(y ~ as.numeric(x), data = df)
abline(regline)

HTH,

Bernd



More information about the R-help mailing list