我需要分层散点图和allEffects plot. 以下是一些示例数据:
library("effects")
x<-c(1,2,6,7,4,3,5)
y<-c(5,6,3,6,9,4,4)
a<-as.factor(c(1,1,1,2,2,2,2))
xyplot(y ~ x|a)
lm.y<-lm(y~x*a)
plot(allEffects(lm.y))
需要明确的是,我想在情节上xyplot分层。plot(allEfects...)我会很感激任何建议。
我需要分层散点图和allEffects plot. 以下是一些示例数据:
library("effects")
x<-c(1,2,6,7,4,3,5)
y<-c(5,6,3,6,9,4,4)
a<-as.factor(c(1,1,1,2,2,2,2))
xyplot(y ~ x|a)
lm.y<-lm(y~x*a)
plot(allEffects(lm.y))
需要明确的是,我想在情节上xyplot分层。plot(allEfects...)我会很感激任何建议。
我建议使用 ggplot2 包,它应该看起来像这样。
ggplot(data, aes(y=y, x=x)) +
geom_point(shape = 1) +
geom_smooth(method="lm", fullrange=T) +
facet_grid(~a) +
theme(aspect.ratio = 1)
它将允许您对图进行分层。
话虽如此 - 这不是一个完整的回应,因为我不确定如何合并您的 allEffects() 信息。其他人可能能够提供更好的反馈。
该包latticeExtra提供了几个功能来组合
trellis对象:+.trellis和c.trellis家庭layer
。在这里你需要+.trellis:
library("effects")
library("latticeExtra")
x <- c(1,2,6,7,4,3,5)
y <- c(5,6,3,6,9,4,4)
a <- as.factor(c(1,1,1,2,2,2,2))
pxy <- xyplot(y ~ x|a)
lm.y <- lm(y~x*a)
aef <- allEffects(lm.y)
对象的plot方法efflist(的结果allEffects)存在问题:它只打印trellis对象但不返回。诀窍是使用定义为返回对象的对象(对象的组件)的plot方法
。您的示例的效果可以通过以下方式提取:effefflisttrellisaef[[1]]
peff <- plot(aef[[1]])
最后一步+.trellis:
peff + pxy
