if (FALSE) {
library(modelsummary)
# single model
mod <- lm(hp ~ vs + drat, mtcars)
modelplot(mod)
# omit terms with string matches or regexes
modelplot(mod, coef_omit = 'Interc')
# rename, reorder and subset with 'coef_map'
cm <- c('vs' = 'V-shape engine',
'drat' = 'Rear axle ratio')
modelplot(mod, coef_map = cm)
# several models
models <- list()
models[['Small model']] <- lm(hp ~ vs, mtcars)
models[['Medium model']] <- lm(hp ~ vs + factor(cyl), mtcars)
models[['Large model']] <- lm(hp ~ vs + drat + factor(cyl), mtcars)
modelplot(models)
# add_rows: add an empty reference category
mod <- lm(hp ~ factor(cyl), mtcars)
add_rows = data.frame(
term = "factory(cyl)4",
model = "(1)",
estimate = NA)
attr(add_rows, "position") = 3
modelplot(mod, add_rows = add_rows)
# customize your plots with 'ggplot2' functions
library(ggplot2)
modelplot(models) +
scale_color_brewer(type = 'qual') +
theme_classic()
# pass arguments to 'geom_pointrange' through the ... ellipsis
modelplot(mod, color = 'red', size = 1, fatten = .5)
# add geoms to the background, behind geom_pointrange
b <- list(geom_vline(xintercept = 0, color = 'orange'),
annotate("rect", alpha = .1,
xmin = -.5, xmax = .5,
ymin = -Inf, ymax = Inf),
geom_point(aes(y = term, x = estimate), alpha = .3,
size = 10, color = 'red', shape = 'square'))
modelplot(mod, background = b)
}
Run the code above in your browser using DataLab