[R] axis date format in lattice

karl.sommer at dpi.vic.gov.au karl.sommer at dpi.vic.gov.au
Thu Jan 11 02:07:00 CET 2007


Hello list,

plotting the following example 1 in lattice only labels the x-axis with one
tick mark at the beginning of February.
In contrast the standard plot() function labels the x-axis with equally
spaced tick marks.

#----example 1 -------
library(lattice)
date <- as.Date(c("1/10/2006", "01/11/2006", "01/12/2006",
                  "01/01/2007", "01/02/2007"),format="%d/%m/%Y")
xx <- c(1,3,5,6,7)
xx1 <- as.data.frame(cbind(date, xx))
xyplot(xx~date, scales=list(x=list(format = "%b")))
plot(xx~date)

Interestingly the behaviour in lattice only seems to arise when there is a
change in calendar years.  This is demonstrated by the second example with
dates from within 1 calendar year only where lattice works as expected.

I was wondering if the behaviour in example 1 was due to a bug or am I
missing something and, more importantly, is there a way around it?

#---example 2 -------
date <- as.Date(c("1/08/2006", "01/09/2006", "01/10/2006",
                  "01/11/2006", "01/12/2006"),format="%d/%m/%Y")
xx <- c(1,3,5,6,7)
xx1 <- as.data.frame(cbind(date, xx))
xyplot(xx~date, scales=list(x=list(format = "%b")))
plot(xx~date)

Cheers
Karl

_________________________________
Dr Karl J Sommer,
Department of Primary Industries,
Catchment & Agriculture Services,
PO Box 905
Mildura, VIC, Australia 3502

Tel: +61 (0)3 5051 4390
Fax +61 (0)3 5051 4534

Email:     karl.sommer at dpi.vic.gov.au



More information about the R-help mailing list