The reason that you need the 'as.POSIXct' is that the 'abline' function does not recognize variables with POSIXlt class.
> methods(abline) no methods were found Warning message: In methods(abline) : function 'abline' appears not to be generic > methods(plot) [1] plot.acf* plot.data.frame* plot.Date* plot.decomposed.ts* plot.default [6] plot.dendrogram* plot.density plot.ecdf plot.factor* plot.formula* [11] plot.hclust* plot.histogram* plot.HoltWinters* plot.isoreg* plot.lm [16] plot.medpolish* plot.mlm plot.POSIXct* plot.POSIXlt* plot.ppr* [21] plot.prcomp* plot.princomp* plot.profile.nls* plot.sar plot.spec [26] plot.spec.coherency plot.spec.phase plot.srx.file plot.stepfun plot.stl* [31] plot.table* plot.ts plot.tskernel* plot.TukeyHSD 'plot' knows how to handle POSIXct/lt classes. You need to at least convert to POSIXct since the value will be within the range of what the x-axis is: > str(event.1) POSIXlt[1:9], format: "2009-07-19 15:28:33" > par('usr') [1] 1248015314.4 1248023025.6 58.8 1036.2 > unclass(as.POSIXct(event.1)) [1] 1248017313 attr(,"tzone") [1] "GMT" This shows the extent of the x-axis and then what the value of event.1 will be after conversion to POSIXct. HTH On Sun, Jul 19, 2009 at 11:33 AM, F!!<p...@students.uni-mainz.de> wrote: > > Sorry for the lack of the plot. It's is just a simple xy plot with xvalues > formated as shown in my post (strptime()). > > Anyway, here a working example: > > > >> >> rm(list=ls()) >> >> x<-c(100*1500:1559, 100*1600:1659) >> x<-strptime(x, format="%H%M%S") >> y<-c(CO2$conc, CO2$conc[1:36]) >> >> plot(x, y, pch=18, type="p", ylab="yfoo", xlab="xfoo", yaxs="r") >> >> abline(h=100, v=0, col="gray60", lty=2) >> text.xvalue<-151500 >> text.xvalue<-strptime(text.xvalue, format="%H%M%S") >> text(text.xvalue, 80, "detection threshold", col="gray60", cex=0.8) >> >> event.1<-152833 >> event.1<-strptime(event.1, format="%H%M%S") >> abline(v=event.1, col="red") >> >> > > The format for the xvalues works in the case of text positioning, but > doesn't in the case of abline. > > JimHoltman replied this topic via email with a solution: > > <-as.POSIXct(strptime(y, format="%H%M%S")) > > > I still don't know why this second function is necessary since everything > works without it, except for the abline-thing... > > Nevertheless, thanks for all the suggestions! > > Fritz > -- > View this message in context: > http://www.nabble.com/abline%28v%3D-x%29-in-plot-with-time-formated-xaxis-not-working-tp24505884p24558044.html > Sent from the R help mailing list archive at Nabble.com. > > ______________________________________________ > R-help@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. > -- Jim Holtman Cincinnati, OH +1 513 646 9390 What is the problem that you are trying to solve? ______________________________________________ R-help@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.