Skip to content

Instantly share code, notes, and snippets.

@benwhalley
Created January 5, 2017 10:54
Show Gist options
  • Save benwhalley/56985516177d809082c07c1ff2631616 to your computer and use it in GitHub Desktop.
Save benwhalley/56985516177d809082c07c1ff2631616 to your computer and use it in GitHub Desktop.
p1 <-
ggplot(group.table, aes(month, fit, group=grp, color=grp, shape=grp)) +
geom_point() + geom_line() +
scale_color_discrete("") + scale_shape_discrete("") +
geom_text(show_guide = FALSE, aes(label=fit, y=fit), size=3) +
xlab(paste("Month")) +
ylab(paste("Model adjusted", toupper(dv))) +
theme(legend.position="top") +
theme(axis.text.x=element_blank(),axis.title.x=element_blank())
p2 <-
contrasts.table %>% bind_rows(data_frame(month=ordered("0", levels=paste(c(0,7,12,18)))), .) %>%
ggplot(aes(x=factor(month), y=as.numeric(-SMD), ymin=-`SMD lower`, ymax=-`SMD upper`, group=1)) +
geom_hline(yintercept=0, color="darkgrey") +
geom_errorbar(width=.1, alpha=.4) + geom_point() +
geom_line(alpha=.4, linetype="dotted") +
geom_text(nudge_x=.25, nudge_y=.2, size=3, aes(label=paste("D=", twodigitfixed(-SMD)))) +
xlab(paste("")) +
ylab(paste("SMD, 95% CI"))
p3 <-
rf2main %>% filter(month!="0") %>%
rename_(y = dv, y.b = paste0(dv, ".b")) %>%
mutate(month=factor(month, levels=c("0", "7", "12", "18"))) %>% complete(month, grp) %>%
ggplot(aes(x=grp, y=y-y.b, color=grp, shape=grp)) +
scale_color_discrete("") + theme(legend.position="none") +
geom_hline(yintercept=0, color="grey")+
geom_boxplot(width=.5) +
facet_grid(.~month, switch="both") +
ylab("Change from baseline (raw)") + xlab("Month")
arrangeGrob(ggplotGrob(p1), ggplotGrob(p2), ggplotGrob(p3), heights=c(4,3,4))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment