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

BDM*_*BDM 13 plot r 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")
 )
Run Code Online (Sandbox Code Playgroud)

这给了我以下情节: 在此输入图像描述

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

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")
 )
Run Code Online (Sandbox Code Playgroud)

我们得到了正确的订单 在此输入图像描述

谢谢您的帮助

Rom*_*rik 8

我转换Temp成因子得到了这个:

在此输入图像描述

你可以像这样调整因子顺序:

levels(rate$Temp) <- c("12", "9", "18", "15") #custom factor order
Run Code Online (Sandbox Code Playgroud)

  • @BDM罗马解决方案更好,但这可以用`index.cond`来完成.试试`index.cond = list(c(4,1,2,3))`. (7认同)
  • 为了澄清,格子根据因子的顺序对面板进行排序,并且在创建因子时,默认情况下,它们首先排序.如果你直接从数字变量中创建一个因子,它会做你想要的,但如果你先转换为一个字符,它将按字母数字排序,这就是你发生的事情. (5认同)