Skip to content

problems with abline in a time line scatterplot

2 messages · tilapia, David Winsemius

#
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
#
On Dec 22, 2010, at 6:14 PM, tilapia wrote:

            
So you have either character or numeric variables and very likely the  
column named Date is a character variable.
You will be getting a separate estimate for each separate Date other  
than the first.
The problem lies in your lack of knowledge about how to convert a  
character vector into a data vector as well as you lack of  
understanding regarding lm(). Once you correct these deficits then  
abline will probably work as intended.