[R] Problems plotting and regression w.r.t. date data type on x axis
PIKAL Petr
petr.pikal at precheza.cz
Thu Feb 14 14:23:12 CET 2013
Hi
> -----Original Message-----
> From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-
> project.org] On Behalf Of Kategoricus
> Sent: Thursday, February 14, 2013 12:25 PM
> To: r-help at r-project.org
> Subject: Re: [R] Problems plotting and regression w.r.t. date data type
> on x axis
>
> Hello Petr!
>
> thanks a lot for your help. The plot command plots well, but the abline
> returns without error and does nothing.
>
> > str(tabelle)
> 'data.frame': 4 obs. of 3 variables:
> $ date : Factor w/ 4 levels "2009-01-1","2009-12-1",..: 1 2 3 4 $
> number: int 1673 2111 2487 4301 $ date2 : POSIXlt, format: "2009-01-
> 01" "2009-12-01" ...
As expected date is factor, number is numeric and date2 is POSIXlt format.
> > plot(tabelle$date2,tabelle$number, pch=19, xlab="date of retrieval",
> > ylab="number of animals") regression.punkte<-lm(tabelle$number ~
> > as.Date(tabelle$date)) regression.punkte
Here you are plotting number against POSIX date2.
>
> Call:
> lm(formula = tabelle$number ~ as.Date(tabelle$date))
Here you use date probably converted by as.Date. Why you do not use
lm(number ~ date2, data = tabelle)
which is usual form of model formula.
Try also change date2 by as.POSIXct.
Regards
Petr
>
> Coefficients:
> (Intercept) as.Date(tabelle$date)
> -24046.326 1.799
>
> > abline(regression.punkte, lwd=2)
> >
>
>
>
> --
> View this message in context: http://r.789695.n4.nabble.com/Problems-
> plotting-and-regression-w-r-t-date-data-type-on-x-axis-
> tp4658518p4658529.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.
More information about the R-help
mailing list