Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to change the order of the panels in simple Lattice graphs

Tags:

plot

r

lattice

Hi I am using the following code to generate an xyplot using lattice

xyplot(Rate~Weight|Temp, groups=Week, rate,
 pch=c(15,16,17,3), col=c("blue","red","green","purple"),
 as.table=TRUE,
 xlab="Weight (gr)", ylab="Rate (umol/L*gr)",
 main="All individuals and Treatments at all times",
 strip=strip.custom(strip.names=1),
 key=
 list(text=list(c("Week","1","2","6","8")),
 points=list(pch=c(NA,15,16,17,3),col=c(NA,"blue","red","green","purple")),
 space="right")
 )

This gives me the following plot: enter image description here

Now after changing the code to include panel order as suggested:

xyplot(Rate~Weight|Temp, groups=Week, rate,
 index.cond=list(c(4,1,2,3)),#this provides the order of the panels
 pch=c(15,16,17,3), col=c("blue","red","green","purple"),
 as.table=TRUE,
 xlab="Weight (gr)", ylab="Rate (umol/L*gr)",
 main="All individuals and Treatments at all times",
 strip=strip.custom(strip.names=1),
 key=
 list(text=list(c("Week","1","2","6","8")),
 points=list(pch=c(NA,15,16,17,3),col=c(NA,"blue","red","green","purple")),
 space="right")
 )

and we get the correct order enter image description here

Thanks for the help

like image 999
BDM Avatar asked Jun 15 '11 13:06

BDM


1 Answers

I converted Temp to factor and got this:

enter image description here

You can temper with factor order like so:

levels(rate$Temp) <- c("12", "9", "18", "15") #custom factor order
like image 113
Roman Luštrik Avatar answered Oct 13 '22 12:10

Roman Luštrik