1 Dec 19:29
Help with lattice graphics
From: ravi <rv15i <at> yahoo.se>
Subject: Help with lattice graphics
Newsgroups: gmane.comp.lang.r.general
Date: 2008-12-01 18:30:41 GMT
Subject: Help with lattice graphics
Newsgroups: gmane.comp.lang.r.general
Date: 2008-12-01 18:30:41 GMT
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)
RSS Feed