Skip to content

Instantly share code, notes, and snippets.

@sachsmc
Created November 21, 2017 10:17
Show Gist options
  • Save sachsmc/175937014dabb4385b58e6f8e0de09b0 to your computer and use it in GitHub Desktop.
Save sachsmc/175937014dabb4385b58e6f8e0de09b0 to your computer and use it in GitHub Desktop.
gg forest plots
ggplot(test, aes(x = group.long, y = est, ymin = low, ymax = high, alpha = factor(alpha))) +
geom_hline(yintercept = 1, color = "grey45", linetype = 2) +
geom_hline(yintercept = 0, color = "black") +
geom_text(aes(y = yev, label = ev, alpha = factor(alpha)), size = 3) +
geom_pointrange(shape = 18) + coord_flip() + facet_grid(~ type) +
scale_y_log10(limits = c(1e-3, max(test$high)), breaks = c(0.01, 1, 10), labels = c(0.01, 1, 10)) +
scale_x_discrete(labels = group.labs) +
theme(legend.position = "bottom") +
ylab("Adjusted hazard ratio versus matched general population") +
xlab("") + scale_alpha_manual("", values = c(0, 1)) + guides(alpha = FALSE) + theme_bw() +
theme(panel.grid.major.y = element_line(size = ifelse(rev(myface) == "bold", 3, 0)),
axis.text.y = element_text(face = rev(myface)), strip.text = element_text(size = 8))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment