[R] axis command and excel time format

Gabor Grothendieck ggrothendieck at gmail.com
Wed Nov 8 16:51:17 CET 2006


My understanding is that the main point of your post was how to get times
on the X axis.   hopefully at this point its clear how to do that and you can
come up with some algorithm to put whatever points you want on.

Here is a slight generalization although you will likely have to generalize
it further.

> library(zoo)
> library(chron)
> tt <- c("23:05:02", "23:10:02", "23:15:03", "23:20:03", "23:25:03",
+    "23:30:03", "23:35:03", "23:40:03", "23:45:04", "23:50:04", "23:55:03",
+    "23:55:03")
> x <- c(0.575764, 0.738379, 0.567414, 0.663436, 0.599834, 0.679571,
+    0.88141, 0.868848, 0.969271, 0.878968, 0.990972, 0.990972)
> z <- zoo(x, times(tt))
> mn <- times("23:00:00")
> mx <- times("23:55:00")
> n <- 12
> xt <- times(seq(mn, mx, length = n))
> xt <- times(unique(sub("..$", "00", xt)))
> plot(z, xaxt = "n")
> axis(1, xt, sub(":00$", "", xt))
> R.version.string
[1] "R version 2.4.0 Patched (2006-10-24 r39722)"
> packageDescription("zoo")$Version
[1] "1.2-1"
> packageDescription("chron")$Version
[1] "2.3-9"
>


On 11/8/06, Carmen Meier <carmei3 at web.de> wrote:
> Gabor Grothendieck schrieb:
> > Is the problem how to produce an axis with a given minimum tick,
> > maximum tick and given number of ticks?  In that case try this
> yes but ... ;-)
> I started with an plain R gui
>
> library(zoo)
> library(chron)
> # input data
> # z is from original example
> mn <- times("23:00:00")
> mx <- times("23:55:00")
> n <- 12
> z <-(1:50)
> xt <- times(seq(mn, mx, length = n))
> plot(z, xaxt = "n")
> axis(1, xt, sub(":00$", "", xt))
>
>
> The result is an X-axes with 23:00 at the left side nothing else at the
> x-axis

Not for me.  It gives ticks all along the x axis for me.  I have placed
the entire self contained code above just to be sure.

> That`s just the same problem as I got with further trials of my own
> and a minor problem will be sub(":00$", "", xt)) if
> times(seq(mn, mx, length = n)) will not result
> xx:yy:00 values only (f.e n=17)
>
> Regards Carmen
>



More information about the R-help mailing list