Plotting predicted values from lmer as a single plot

放肆的年华 提交于 2019-12-03 09:56:15

How about:

library(effects)
library(lme4)
library(ggplot2)
m1 <- lmer(price~depth*cut+(1|cut),diamonds)

By the way, note that this particular model makes no sense (factor included both as fixed and random term)! I hope you're only using it as an illustration ...

ee <- Effect(c("cut","depth"),m1) 

The key is using as.data.frame() to turn the effects object into something useful ...

theme_set(theme_bw())
ggplot(as.data.frame(ee),
       aes(depth,fit,colour=cut,fill=cut))+
    geom_line()+
     ## colour=NA suppresses edges of the ribbon
    geom_ribbon(colour=NA,alpha=0.1,
                            aes(ymin=lower,ymax=upper))+
     ## add rug plot based on original data
        geom_rug(data=ee$data,aes(y=NULL),sides="b")

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!