Skip to content

Instantly share code, notes, and snippets.

@mikelove
Created October 7, 2014 15:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mikelove/3816eac0e05702e2ee08 to your computer and use it in GitHub Desktop.
Save mikelove/3816eac0e05702e2ee08 to your computer and use it in GitHub Desktop.
broom and ggplot2
library(broom)
library(ggplot2)
tidyfit <- tidy(fit)
tidyfit$xmin <- with(tidyfit, estimate - stderror)
tidyfit$xmax <- with(tidyfit, estimate + stderror)
ggplot(tidyfit, aes(x=estimate,y=term,xmin=xmin,xmax=xmax,height=0)) +
geom_point() + geom_vline(xintercept=0) + geom_errorbarh()
@dgrtwo
Copy link

dgrtwo commented Oct 7, 2014

Nice! With dplyr/magrittr it can be even more space-efficient:

library(dplyr)
tidyfit <- fit %>% tidy() %>%
    mutate(xmin = estimate - stderror, xmax = estimate + stderror)

(dplyr also makes it easier to perform regressions on subgroups or replications).

@dgrtwo
Copy link

dgrtwo commented Oct 19, 2014

Please note that as of version 0.3, the stderror column has been changed to std.error.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment