Skip to content
Prev 76665 / 398502 Next

time series graphs

On 9/4/05, Anette N??rgaard <anette at geoplus.dk> wrote:
If you are going to be doing a lot of time series
manipulations that have dates and times then read
R News 4/1 Help Desk for an article about dates/times
and read the zoo vignette for information on zoo.

library(zoo)
vignette("zoo")


You don't seem to have enough room to label the hours
but you could label the days and just put ticks for
the hours.

Create a zoo series using chron dates and times and just
plot it.  That may be sufficient.

library(chron)
library(zoo)

# convert date/times to chron
tt <- chron(paste(1,1,dat[,1],sep="/"),dat[,3]/24)+dat[,2]-1

# create a zoo series using your data and the chron dates/times
z <- zoo(dat[,4:5],tt)

plot(z, plot.type = "single")

# Alternative.
# If you want more control, plot it without the X axis
# and use axis twice to draw the X axis yourself.  Use the
# tcl= argument to vary the tick sizes.

plot(z, plot.type = "single", xaxt = "n")

# X axis labelling days
dd <- seq(min(floor(tt)), max(floor(tt)))
axis(1, dd, format(as.Date(dd), "%b %d"), tcl = -0.6)

# X axis with just ticks for hours
hh <- seq(min(tt), max(tt), by = 1/24)
axis(1, hh, FALSE, tcl = -0.4)