Last active
September 27, 2018 19:45
-
-
Save haozhu233/fe518e6ef5e94e37f30d593dc54c9fe3 to your computer and use it in GitHub Desktop.
forest plot with grouping need
This file contains hidden or 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
library(broom) | |
library(tidyverse) | |
library(viridis) | |
fit <- lm(mpg ~ ., data = mtcars) | |
fit_dt <- tidy(fit, conf.int = T) | |
# reverse the order so it looks right on plot | |
fit_dt$term <- factor(fit_dt$term, rev(fit_dt$term)) | |
# I'm creating some fake grouping info | |
fit_dt$cat <- c(rep("type a", 4), rep("type b", 4), rep("type c", 3)) | |
ggplot(fit_dt, aes(x = term, y = estimate, ymin = conf.low, ymax = conf.high)) + | |
geom_hline(yintercept = 0, color = "gray") + | |
geom_pointrange(aes(color = cat)) + | |
coord_flip() + | |
theme_classic() + | |
scale_color_viridis(end = 0.8, discrete = T) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment