[R] xyplot format axis

Deepayan Sarkar deepayan.sarkar at gmail.com
Tue Jun 16 23:24:40 CEST 2009


On Tue, Jun 16, 2009 at 7:24 AM, taz9<alienz747 at gmail.com> wrote:
>
> Hi All,
>
> I'm trying to format the y-axis in an xyplot to show numbers with a comma
> separating the thousands but I'm not able to do it using formatNum(y,
> big.mark=","). This is what I have:
>
> library(lattice)
>
> year<-c(2003,2004,2005,2006,2007,2008,2003,2004,2005,2006,2007,2008)
> dept<-c("Politics","Politics","Politics","Politics","Politics","Politics","Sociology","Sociology","Sociology","Sociology","Sociology","Sociology")
> awards<-c(859742,1346337,1841238,1104794,2192130,237253,1736600,1570843,4947761,4587803,2314805,2762599)
> df1<-data.frame(year,dept,awards)
>
> xyplot(awards~year|dept, data=df1, type="o",
> scales=list(y=list(alternating=3),x=list(alternating=1)),
>          panel = function(...) {
>             panel.grid(h = -1,v = 0, lty="dotted")
>             panel.xyplot(...)
> })
>
> Any ideas are much appreciated.

Something like

xyplot(awards~year|dept, data=df1, type="o",
       yscale.components = function(...) {
            yc <- yscale.components.default(...)
            yc$left$labels$labels <-
                format(yc$left$labels$at, scientific = FALSE, big.mark = ",")
            yc
       })

-Deepayan




More information about the R-help mailing list