Message-ID: <CC664651-D0DC-49F6-9380-3FF7BC18307E@comcast.net>
Date: 2014-08-06T21:30:51Z
From: David Winsemius
Subject: lattice scales format dates
In-Reply-To: <63F107BCC37AEA49A75FD94AA3E07CB00F84E296@pacpbsex01.pac.dfo-mpo.ca>
On Aug 6, 2014, at 1:11 PM, Folkes, Michael wrote:
> Hello all,
>
> Based on the help in ?xyplot,
Which says very little about barchart in particular but rather refers you to
?panel.barchart
It's really designed expecting x to be a factor,
> and this suggestion from another request:
>
> http://stackoverflow.com/questions/20623041/r-formatted-auto-scaling-dat
> e-axis-using-lattice
>
> I was under the impression that this code should give me the desired x
> axis label date format of: "1911-Jan".
Probably would have if you were using xyplot. But barchart's author assumed that the "x-axis" is a set of disjoint values and that's not really how datetimes are generally considered. Try this:
barchart(var1~factor(format(date.val, "%Y-%b")), data=dat, horizontal=F,
scales=list(x=list(rot=45) ) )
>
>
>
> dat <- data.frame(var1=1:10,
> date.val=as.POSIXct(seq(as.Date("1910/11/1"), as.Date("1911/8/1"),
> "months") ))
>
> barchart(var1~date.val, data=dat, horizontal=F,
> scales=list(x=list(rot=45, format="%Y-%b")))
>
> format(dat$date.val,"%Y-%b")
And learn to post in plain text.
>
> [[alternative HTML version deleted]]
David Winsemius
Alameda, CA, USA