[R] Odp: newbie needs help plotting time series

Petr PIKAL petr.pikal at precheza.cz
Tue Jul 1 14:33:12 CEST 2008


"Kathi" <kathi at dropnet.ch> napsal dne 01.07.2008 13:39:18:

> Thanks, Petr. 
> 
> After fiddling around some more with my code I found out that this seems 
to 
> have something to do 
> with the number of records the table I'm reading (here: column B112). 
Somehow,
> changing the 
> number of records for B112 changes the numbers in the error message - 
though I
> don't quite 
> understand how the number of records influences the axis intervals or 
their 
> labels, since I define 
> those explicitly...

Neither I. So I sent it to r-help maybe somebody else will know. If you 
debug code of axis.Date you find that after some computing there is this 
comparison where range is based on your input data (in your case x), and z 
is from defined at sequence of dates.

z <- z[z >= range[1] & z <= range[2]]

and this comparison results in character(0), when plotting with this 
artificial example.

plot(1:100, seq(405,410,length=100), axes=FALSE, ylim=c(405,410), 
col="red", pch=15,
type="o", ylab="metres above sea level", main="Main Plot Title")
axis(2, at=405:410, tck=1, col="gray60")
axis.Date(1, at=seq(as.Date("2004-01-01"), as.Date("2008-06-01"), 
by="month"), labels=seq(as.Date("2004-01-01"), as.Date("2008-06-01"),
by="month"), tck=1, col="gray60")

I presume, that your x is from different interval of dates or it is not a 
date.

Regards
Petr


> 
> Kathi
> 
> 
> On Mon, 30 Jun 2008 11:48:43 +0200, Petr PIKAL wrote
> > Hi
> > 
> > r-help-bounces at r-project.org napsal dne 30.06.2008 11:14:48:
> > 
> > > Dear R help list
> > > 
> > > I have recently started using R to visualize time series of water 
level 
> > > measurements. The code I wrote 
> > > does exactly what I want:
> > > 
> > > plot(x, a$B112, axes=FALSE, ylim=c(405,410), col="red", pch=15, 
> > > type="o", ylab="metres above sea level", main="Main Plot Title")
> > > axis(2, at=405:410, tck=1, col="gray60")
> > > axis.Date(1, at=seq(as.Date("2004-01-01"), as.Date("2008-06-01"), 
> > > by="month"), labels=seq(as.Date("2004-01-01"), 
as.Date("2008-06-01"), 
> > > by="month"), tck=1, col="gray60")
> > > 
> > > Now I wanted to shift the data visualized by 6 months, so I replaced 

> > > "2004-01-01" by "2004-07-01" 
> > > and "2008-06-01" by "2008-12-01". Instead of the desired plot, I get 
an 
> > error 
> > > message stating 
> > > (forgive the perhaps faulty translation into English, I'm working on 
a 
> > German 
> > > version of R):
> > > 
> > > mistake in axis(side, at = z, labels = labels, ...) : 
> > >   length of 'at' and 'labels' different, 50 != 54
> > 
> > Those two calls have different length
> > 
> > at=seq(as.Date("2004-01-01"), as.Date("2008-06-01"), by="month")
> > labels=seq(as.Date("2004-01-01"), as.Date("2008-06-01"), by="month")
> > 
> > you can try it by
> > 
> > length(seq(...))
> > 
> > could not there be some typo in your call?
> > 
> > Regards
> > 
> > Petr
> > 
> > > 
> > > What have I done wrong? Thank you very much for your help!
> > > 
> > > Katharina Dubach
> > > 
> > > ______________________________________________
> > > 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.
> 
> 
> --
> DropNet AG - Das Unternehmen fuer Ihren Internet-Auftritt!
> 
>



More information about the R-help mailing list