relabel_predictors: Relabel the Predictors in a Tidy Data Frame of Regression...

Description Usage Arguments Value Examples

View source: R/relabel_predictors.R

Description

relabel_predictors is a convenience function for relabeling the predictors in a tidy data frame to be passed to dwplot or a plot generated by dwplot

Usage

1

Arguments

x

Either a tidy data frame to be passed to dwplot or a plot generated by dwplot.

...

Named replacements, as in recode. The argument names should be the current values to be replaced, and the argument values should be the new (replacement) values. For backwards compatibility, a named character vector, with new values as values, and old values as names may also be used. The order of the named replacements will be preserved, so this function also serves the purpose of reordering variables.

Value

The function returns an object of the same type as it is passed: a tidy data frame or a plot generated by dwplot.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
library(broom)
library(dplyr)

data(mtcars)
m1 <- lm(mpg ~ wt + cyl + disp, data = mtcars)
m1_df <- broom::tidy(m1) %>%
         relabel_predictors("(Intercept)" = "Intercept",
                              wt = "Weight",
                              disp = "Displacement",
                              cyl = "Cylinder")
dwplot(m1_df)

dwplot(m1, show_intercept = TRUE) %>%
    relabel_predictors("(Intercept)" = "Intercept",
                              wt = "Weight",
                              disp = "Displacement",
                              cyl = "Cylinder")

dotwhisker documentation built on Sept. 5, 2021, 5:08 p.m.