[R] Lattice(barchart) related query

David Winsemius dwinsemius at comcast.net
Wed Jun 3 16:42:16 CEST 2009


On Jun 3, 2009, at 9:56 AM, Girish A.R. wrote:

> Hi,
>
> I have been recently experimenting with the lattice package, which I
> must admit is just great! However, I'm sort of stuck in modifying
> certain parameters; Would appreciate some pointers on a couple of
> things:
>
> 1) Is it possible to change the font of the labels (say to computer
> modern)  -- either in the Windows output or thru' Sweave (generating
> EPS/PDF)?
> 2) As you will notice, there are negative values in the data. Is it
> possible to have a different color for the bars depicting negative
> values?
>
> Reproducible code pasted below:
> ------------------------------------------------------------------------------------------
> mdat <- matrix(c
> (-2.65,-3.7,-0.8,-1.4,-2.39,-1.12,-4.78,-4.9,-0.76,-1.56,
> 1.77,1.41,1.92,1.78,0.05,0.96,0.29,1.4,0.53,1.49,
> 1.4,0.35,1.65,2.14,1.88,2.75,1.86,0.32,2.96,2.28), nrow = 3, ncol=10,
> byrow=TRUE, dimnames = list(c("A", "B","C"),c
> ("S-1","S-2","S-3","S-4","S-5","S-6","S-7","S-8","S-9","S-10")))
>
> barchart(mdat, groups=FALSE,layout=c
> (2,5),aspect=0.7,reference=FALSE,as.table=TRUE,main=list("Main
> title",cex=1),xlab="x-axis labels")

In you particular instance, I can accomplish the task but I do not  
know how to do it in a more general fashion, because I do not know how  
to access the values for the labels internally needed so that an  
ifelse() test can be constructed. See it this is helpful at any rate:

barchart(mdat, groups=FALSE,layout=c(2,5), aspect=0.7,  
reference=FALSE, as.table=TRUE, main=list("Main
title",cex=1),xlab="x-axis  
labels",scales=list(x=list(col=c("red","red","black","black"))) )

Deepayan will probably be along shortly with the complete answer.

Regards;
David

David Winsemius, MD
Heritage Laboratories
West Hartford, CT




More information about the R-help mailing list