Skip to content
Back to formatted view

Raw Message

Message-ID: <63F107BCC37AEA49A75FD94AA3E07CB00F84E394@pacpbsex01.pac.dfo-mpo.ca>
Date: 2014-08-06T21:45:14Z
From: Folkes, Michael
Subject: lattice scales format dates
In-Reply-To: <CC664651-D0DC-49F6-9380-3FF7BC18307E@comcast.net>

Thanks David.
Much appreciated.


-----Original Message-----
From: David Winsemius [mailto:dwinsemius at comcast.net] 
Sent: August-06-14 2:31 PM
To: Folkes, Michael
Cc: r-help at r-project.org
Subject: Re: [R] lattice scales format dates


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-d
> at
> 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