Skip to content

Instantly share code, notes, and snippets.

@dpastoor
Created August 14, 2013 15:02
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dpastoor/6231895 to your computer and use it in GitHub Desktop.
Save dpastoor/6231895 to your computer and use it in GitHub Desktop.
Example forest plot using ggplot2
library(ggplot2)
dat <- data.frame(group = factor(c("Infliximab","Etanercept","Adalimumab","Golimumab","Certolizumab","Abatacept","Rituximab","Tocilizumab","Total"),
levels=c("Total","Certolizumab","Golimumab","Adalimumab","Etanercept","Infliximab","Tocilizumab","Rituximab","Abatacept")),
cen = c(1.88,2.67,2.35,2.14,5.08,1.68,2.11,2.01,2.16),
low = c(1.01,1.44,1.52,1.59,3.46,1.47,1.64,1.57,1.83),
high = c(3.51,4.94,3.65,2.89,7.48,1.90,2.72,2.57,2.55))
p_eff <- ggplot(dat,aes(cen,group)) +
geom_point(size=5, shape=18) +
geom_errorbarh(aes(xmax = high, xmin = low), height = 0.15) +
geom_vline(xintercept = 1, linetype = "longdash") +
scale_x_continuous(breaks = seq(0,14,1), labels = seq(0,14,1)) +
labs(x="Favours Experimental", y="") +
theme(text = element_text(size=20)) +
ggtitle("Risk Ratio for ACR20 response at 6 months")
p_eff
dat2 <- data.frame(group =
factor(c("Infliximab","Etanercept","Adalimumab","Golimumab","Certolizumab","Total"),
levels=c("Total","Certolizumab","Golimumab","Adalimumab","Etanercept","Infliximab")),
cen = c(3.22,0.71,1.59,0.98,2.72,1.26),
low = c(1.76,0.54,1.13,0.46,1.23,0.93),
high = c(5.91,0.92,2.23,2.08,6.01,1.71))
p_saf <- ggplot(dat2,aes(cen,group)) +
geom_point(size=5, shape=18) +
geom_errorbarh(aes(xmax = high, xmin = low), height = 0.15) +
geom_vline(xintercept = 1, linetype = "longdash") +
scale_x_continuous(breaks = seq(0,14,1), labels = seq(0,14,1)) +
labs(x="Favours Control", y="") +
theme(text = element_text(size=20)) +
ggtitle("Risk Ratio for ACR50 response at 6 months for anti TNF-alpha
drugs")
p_saf
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment