library("tinyplot")
= lm(mpg ~ wt * factor(am), mtcars)
mod = data.frame(names(coef(mod)), coef(mod), confint(mod))
coefs colnames(coefs) = c("term", "est", "lwr", "upr")
= tpar(pch = 19)
op
# "errorbar" and "pointrange" type convenience strings
tinyplot(est ~ term, ymin = lwr, ymax = upr, data = coefs, type = "errorbar")
tinyplot(est ~ term, ymin = lwr, ymax = upr, data = coefs, type = "pointrange")
# Use `type_errorbar()` to pass extra arguments for customization
tinyplot(est ~ term, ymin = lwr, ymax = upr, data = coefs,
type = type_errorbar(length = 0.2))
# display three models side-by-side with dodging
= list(
models "Model A" = lm(mpg ~ wt + cyl, data = mtcars),
"Model B" = lm(mpg ~ wt + hp + cyl, data = mtcars),
"Model C" = lm(mpg ~ wt, data = mtcars)
)
= lapply(names(models), function(m) {
results data.frame(
model = m,
term = names(coef(models[[m]])),
estimate = coef(models[[m]]),
setNames(data.frame(confint(models[[m]])), c("conf.low", "conf.high"))
)
})= do.call(rbind, results)
results
tinyplot(estimate ~ term | model,
ymin = conf.low, ymax = conf.high,
data = results,
type = type_pointrange(dodge = 0.2))
# Note that the default dodged position is based solely on the number of
# groups (here: models) available to each coefficient term. To fix the
# position consistently across all terms, use `fixed.pos = TRUE`.
tinyplot(estimate ~ term | model,
ymin = conf.low, ymax = conf.high,
data = results,
type = type_pointrange(dodge = 0.2, fixed.pos = TRUE))
tpar(op)