Quick and easy dot-and-whisker plots of regression results.
dwplot is a function for quickly and easily generating dot-and-whisker plots of regression models saved in tidy data frames. It provides a convenient way to create highly customizable plot for presenting and comparing statistics. Users can use it to plot coefficients or other estimates (e.g., predicted probabilities) within a model or compare them across different models. The estimates are presented as dots with confidential interval whiskers, and grouped based on variables.
More detail are introducted at:
vline argument is now available for
dwplot(). Passing a
geom_vline() object to this argument, typically one with
xintercept = 0, will plot this line behind the plotted coefficients, which most will find aesthetically preferable. The default for this argument is
NULL, so if you prefer not to include such lines or just like them plotted last and foremost, there's no need to change your code.
dwplot() now again accepts the
whisker_arg argument to change the appearance of the whiskers representing the confidence intervals that has been lost since v0.3.0. This means you can, for example, specify different colors for the dots and the whiskers:
# load the librarylibrary(dotwhisker)#> Loading required package: ggplot2# linear model of interestlm_object <- stats::lm(formula = wt ~ am * cyl, data = mtcars)# creating the plot with dwplotdwplot(x = lm_object,dot_args = list(color = "red"), # color for the dotwhisker_args = list(color = "black"), # color for the whiskervline = ggplot2::geom_vline(xintercept = 0, # put vline _behind_ coefscolour = "grey60",linetype = 2,size = 1))
Created on 2018-06-27 by the reprex package (v0.2.0).
add_brackets()that caused brackets to overlap in large models or when many models were included in a single plot.
style = "distribution"in the arguments to
dwplot()presents regression coefficients as normal distributions, underscored with a line representing the desired confidence interval.
relabel_predictors()now conveniently reorders the predictors as well.
add_brackets()can now be added directly to the end of a chain of commands that generate a dotwhisker plot; the intermediate object necessary in past versions is no longer needed. Just wrap the plotting commands in braces (
}) before piping them to
dwplot()should no longer be used to change the width of confidence intervals; use
conf.int(to be passed to
dwplot()is passed model objects rather than a tidy data frame, the regression coefficients are now rescaled by two standard deviations of their respective variables in the analysed data (per
by_2sd()) by default. This may be changed by setting
by_2sd = FALSE.
add_brackets()that de-centered the brackets
dot_argsto be ignored after plots were passed to
small_multiple()from directly reading confidence intervals from a model.
by_2sd()now adjusts, if present, any confidence intervals in tidy data frames passed to the function.
ggstancefunctions. The new
dwplotallows cooperating with more
ggplotfunctions, such as
relabel_predictorsnow accepts plots as well as tidy dataframes as input; that is, it may now be used both before and after calls to
relabel_y_axis. It is easy to mistakenly mislabel variables with
relabel_y_axis, and it has a conflict with
add_bracketsin single-model plots.
More details about the new functions are available in the vignette.