【发布时间】:2021-03-02 07:46:52
【问题描述】:
我正在尝试使用 emmeans 的输出创建一个图形,为一个因子的 5 个水平绘制线条。我希望每个功能区的范围与出现该级别的 x 轴上的数据范围相对应,而不是在整个 x 轴上。即,某些因素仅在 x 轴的特定范围内具有数据,我不想推断超出这些范围。
在整个范围内推断的当前代码是:
newdata=emmeans(model, ~x|factor, at=list(factor=levels(data$factor), x=seq(min(data$x), max(data$x), len=100)), type='response') %>% as.data.frame
figure=ggplot(data, aes(y=y, x=x, color=factor, fill=factor))+
geom_ribbon(data=newdata, aes(x=x, y=response,ymin=lower.CL, ymax=upper.CL), alpha=0.3, colour = NA)+
geom_line(data=newdata, aes(x=x, y=response))
figure
【问题讨论】: