Last active
July 31, 2019 06:25
-
-
Save webbedfeet/7031404fc3f500f6258e to your computer and use it in GitHub Desktop.
Forest plots using R and ggplot2
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
credplot.gg <- function(d){ | |
# 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 | |
require(ggplot2) | |
p <- ggplot(d, aes(x=x, y=y, ymin=ylo, ymax=yhi))+ | |
geom_pointrange()+ | |
geom_hline(yintercept = 0, linetype=2)+ | |
coord_flip()+ | |
xlab('Variable') | |
return(p) | |
} |
Hello Abhijit,
Thank you for posting this function, I found it very helpful. However, I have an additional request, if you would be so kind.
I would like to include a second center point and confidence limits under the same variable name (possibly shaded with a different colour). I could format the data frame input to have column headings of d$y1, d$y2, d$y1lo, d$y2lo, d$y1hi, and d$y2hi, all under the same variable name (d$x).
Would this require alot of changes to your current function?
Abdool
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The code from today works with R 3.2.0 and ggplot2 2.0.0