对于xyplot行,格子分开y轴

时间:2014-10-31 15:55:44

标签: r lattice

我希望对具有2乘2显示的xyplot行具有相同的y轴限制。 scales = "free"scales = "sliced"都不会达到此目的。

玩具示例

size <- rep(c("da","db","ca","cb"),each=5)  
age <- rep(1:5,4)  
growth <- rep(c(-75,-55,-25,-20),each=5)  

test <- data.frame(size,age,growth)


xyplot(growth~age|factor(size),layout=c(2,2),
 type=c("p","g"),
 scales=list(x=list(tick.number=3)),
 ylab="growth %",xlab="age",pch=20,col="black",
 data=test)

在这种情况下,我希望(在基本图形中):第一行为ylim=c(-50,-80),第二行为y=c(-20,-30)

1 个答案:

答案 0 :(得分:2)

您需要将限制列表传递给xyplot。在这里,我在xyplot函数之外创建了一个列表,但如果您愿意,可以在scales参数中执行此操作。

library(lattice)
size <- rep(c("da","db","ca","cb"),each=5) 
age <- rep(1:5,4)
growth <- rep(c(-75,-55,-25,-20),each=5)
test <- data.frame(size,age,growth)

YLims<-list(c(-20,30),c(-20,30),c(-50,-80),c(-50,-80) )

xyplot(growth~age|factor(size),
   layout=c(2,2), 
   type=c("p","g"), 
   scales=list(x=list(tick.number=3), y=list(relation="free", limits=YLims)), 
   ylab="growth %",xlab="age",pch=20,col="black",  data=test)

enter image description here