ravi | 1 Dec 19:29

Help with lattice graphics

Hi,
I like the formatting and the appearance of lattice plots. But I have not succeeded in gettting the right
format in my plots with the lattice package in one of my applications. In the code shown below, I start by
constructing a general data frame and show my attempts with the lattice package commands. After that, I
use the graphics package and show the kind of plot that I want to get.

I would like to know how the lattice commands can be modified to get the final plot that I have obtained with
the graphics package. Any explanatory comments to understand better the modifications are most welcome.

Here is my code :
##########################################################
rm(list=ls())
# make up a test data frame with 4 columns
# factors in first 3 cols and a numeric in the 4th
vec_a<-paste("A",1:4,sep=(''));na<-length(vec_a)
vec_b<-paste("B",1:5,sep=(''));nb<-length(vec_b)
yr<-c("2007","2008","2009");ny<-length(yr)
fac_a<-factor(vec_a);fac_b<-factor(vec_b);fac_yr<-factor(yr)
n<-na*nb*ny
# y is the response variable
y<-runif(n);y<-round(y,digits=1)
dfa<-rep(fac_a,times=nb*ny)
dfb<-rep(fac_b,each=na,times=ny)
dfyr<-rep(fac_yr,each=na*nb)
dataf<-data.frame(dfa=dfa,dfb=dfb,dfyr=dfyr,y=y);head(dataf)
# dataf is the test data frame
# First test with the lattice package
library(lattice)
barchart(y~dfb|dfyr,dataf,layout=c(3,1),beside=FALSE,
          groups=dfa,
(Continue reading)

baptiste auguie | 1 Dec 20:00

Re: Help with lattice graphics


Hi,

The main difference I saw between your two graphs was the stacking,  
which you can obtain by stack=TRUE in lattice. I'm not sure what  
cosmetic issues you had in mind. Perhaps you can try this,

> barchart(y~dfb|dfyr,dataf,layout=c(3,1),stack=T,ylim=c(0, 2.7),

>          groups=dfa, strip = strip.custom(var.name="year",  
> strip.names = c(TRUE, TRUE)),
>          scales=list(x=list(rot=0), y=list(axs="i", at=seq(0, 2.5,  
> by=0.5))),
>          par.settings=list(axis.text=list(font=2,cex=0.75),
>                              par.ylab.text=list(font=2,cex=1.0),
>                              par.xlab.text=list(font=2,cex=1.0),
>                              par.main.text=list(font=2,cex=1.0)),
>          xlab="b",
>          ylab="y",auto.key = list(space="top",  
> columns=length(levels(dataf$dfa))),
>          main="A test lattice plot")

Baptiste

On 1 Dec 2008, at 18:30, ravi wrote:

> Hi,
> I like the formatting and the appearance of lattice plots. But I  
> have not succeeded in gettting the right format in my plots with the  
> lattice package in one of my applications. In the code shown below,  
(Continue reading)


Gmane