On Dec 22, 2010, at 6:14 PM, tilapia wrote:
>
> 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)
So you have either character or numeric variables and very likely the
column named Date is a character variable.
> 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")
>
You will be getting a separate estimate for each separate Date other
than the first.
> 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,
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.
--
David
> or is there a possibiliy to solve it with
> the way i started it?
>
>
> thank you for any guidance!
>
> Chris
>
>
> --
> View this message in context:
http://r.789695.n4.nabble.com/problems-with-abline-in-a-time-line-scatterplot-tp3161401p3161401.html
> Sent from the R help mailing list archive at Nabble.com.
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.