r - plot lmer result in faceted ggplot -
i'm analysing repeated measures drug trials data , i'm not sure how plot lmer results when using faceted ggplots. have made initial plot of individual slopes master dataset, i'm doing lmer analyses separately sex.
using publicly available data, has 2 treatment groups compared 4 have, replicable example below. uses reshape2
, lme4
, , ggplot2
packages.
catanx <- read.fwf(file=("http://www.stat.ufl.edu/~winner/data/cats_anxiety1.dat"), widths=c(-6,2,-5,3,-5,3,-7,1,-7,1,-7,1,-7,1,-7,1,-6,2,-6,2,-6,2,-6,2,-6,2)) colnames(catanx) <- c('id','weight','age_months','gender','environment','origin','treatment','result','emotime1','emotime2', 'emotime3','emotime4','emotime5') library("reshape2") catanxrm <- melt(catanx, id.vars=c("id", "gender", "treatment"), measure.vars=c("emotime1", "emotime2", "emotime3", "emotime4", "emotime5")) catanxrm$sex <- with(catanxrm, ifelse(gender==1, "neut female", ifelse(gender==2, "neut male", "whole female"))) catanxrm$time <- with(catanxrm, ifelse(variable=="emotime1", 1, ifelse(variable=="emotime2", 2, ifelse(variable=="emotime3", 3, ifelse(variable=="emotime4", 4,5))))) catanxrm.male <- subset(catanxrm, gender=="2") library("lme4") male.lmer <- lmer(value ~ treatment * time + (time + 1|id), data=catanxrm.male) library("ggplot2") anxscores<-ggplot(catanxrm, aes(time, value, colour=sex))+ geom_line(aes(group = id))+ labs(x="time anxiety measured", y="anxiety score", title="effect of zylkene on anxiety")+ facet_grid(. ~ treatment) anxscores
information dataset is here.
how plot correct summary line lmer in both facets, differ on basis of treatment
?
in real life example, i'll analysing females there 2 sets of lines plot per facet.
create data frame (e.g. lines.df
) intercept (e.g. int
) , slope (slo
) variables each line of df corresponds 1 facet, plot on top:
+ geom_abline(aes(intercept = int, slope = slo), data = lines.df)
Comments
Post a Comment