Here's the R code, slightly modified from Abhijit's version:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# d is a data frame with 4 columns | |
# d$x gives variable names | |
# d$y gives center point | |
# d$ylo gives lower limits | |
# d$yhi gives upper limits | |
forestplot <- function(d, xlab="Odds Ratio", ylab="Study"){ | |
require(ggplot2) | |
p <- ggplot(d, aes(x=x, y=y, ymin=ylo, ymax=yhi)) + | |
geom_pointrange() + | |
coord_flip() + | |
geom_hline(aes(x=0), lty=2) + | |
ylab(xlab) + | |
xlab(ylab) #switch because of the coord_flip() above | |
return(p) | |
} | |
# Create some dummy data. | |
d <- data.frame(x = toupper(letters[1:10]), | |
y = rnorm(10, .05, 0.1)) | |
d <- transform(d, ylo = y-1/10, yhi=y+1/10) | |
forestplot(d) |
And here's what you get:
Thanks for sharing the code, Abhiji!