如何在简单的莱迪思图中更改面板的顺序

时间:2011-06-15 13:58:14

标签: r plot lattice

您好我正在使用以下代码使用lattice

生成xyplot
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")
 )

这给了我以下情节: enter image description here

现在更改代码后按照建议包含面板顺序:

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")
 )

我们得到正确的订单 enter image description here

感谢您的帮助

1 个答案:

答案 0 :(得分:8)

我将Temp转换为因子并得到了这个:

enter image description here

您可以使用因子顺序调整:

levels(rate$Temp) <- c("12", "9", "18", "15") #custom factor order