Actually, here is the example from ?plot_coefs(). I can demonstrate what I mean using these data.
Here is the jtools way of doing things:
library(jtools)
states <- as.data.frame(state.x77)
fit1 <- lm(Income ~ Frost + Illiteracy + Murder +
Population + Area + `Life Exp` + `HS Grad`,
data = states, weights = runif(50, 0.1, 3))
# horizontal plot
plot_coefs(fit1)
# vertical plot by flipping the coordinates
plot_coefs(fit1) + ggplot2::coord_flip()
Now, lets build the plot from scratch without using the jtools helper function:
library(ggplot2)
library(dplyr)
data <- broom::tidy(fit1, conf.int = TRUE)
# Let's recreate the plot_coefs() plot using only ggplot2 code
data %>%
# Remove intercept (optional)
filter(!term %in% '(Intercept)') %>%
ggplot() +
# add line at null of 0
geom_hline(yintercept = 0, lty = 2) +
# add error bars for confidence interval
geom_segment(aes(x = term, xend = term,
y = conf.low, yend = conf.high), colour = 'dodgerblue',
size = 0.75) +
# add points for the coefficient estimates
geom_point(aes(term, estimate),
fill = 'white', colour = 'dodgerblue', shape = 21,
size = 3, stroke = 1) +
# label axes
labs(y = '', x = 'term') +
# use built-in ggplot2 theme
theme_minimal() +
# add some final touches by customizing the theme
theme(
panel.grid = element_blank(),
panel.grid.major.x = element_line(colour = '#dddddd'),
axis.title.x = element_text(face = 'bold')
)
Yes, the ggplot2 way of doing things was much more code, but I had complete control over every aspect of the plots aesthetic. Anything can be changed to your preference.