Skip to content
Prev 245635 / 398503 Next

problems with abline in a time line scatterplot

Hello R-Users

i'm stuck with the following problem:
i want to add a trend line to a scatterplot. the x axis is a time line.
well it doesnt work, it seems that the function abline is not able
to handle the fact, that i used the column Date as a factor.

this is the script:

data<-read.table('DO_hapa_all_morning.txt',header=T,as.is=2)
attach(data)
names(data)
plot(DO,axes=F,xlab="Date",ylab="DO [mg/l]",ylim=c(0,12),col="red")
axis(1,at=1:length(DO),labels=Date)
axis(2)
abline(lm(DO~Date),col="red")

this warning message shows up (last row translated from german):

warning:
1: In model.matrix.default(mt, mf, contrasts) :
  variable 'Date' converted to a factor
2: In abline(lm(DO ~ Date), col = "red") :
  use only the first two of 54 regression coefficients


is abline not the right function, or is there a possibiliy to solve it with
the way i started it?


thank you for any guidance!

Chris