fsolt / dotwhisker

Dot-and-Whisker Plots of Regression Results
https://fsolt.org/dotwhisker/
Other
57 stars 10 forks source link

ordering doesn't work with more than one regression #85

Closed chr1swallace closed 6 years ago

chr1swallace commented 6 years ago

If I use order_vars with a list of regressions, only the first gets plotted. I think that's because in this line in dwplot, match() selects the first match https://github.com/fsolt/dotwhisker/blob/2f5fa24235662baf34e4173ab41e9eaee029d5e2/R/dwplot.R#L132

I think this is fixed by replacing the line with

df <- df[order(df$term),]
fsolt commented 6 years ago

Issue confirmed:

library(dotwhisker)
#> Loading required package: ggplot2

m1 <- lm(mpg ~ wt + cyl + disp + gear, data = mtcars)
m2 <- update(m1, . ~ . + hp) # add another predictor
m3 <- update(m2, . ~ . + am) # and another 

dwplot(list(m1, m2, m3), order_vars = c("cyl", "disp", "gear", "wt", "am", "hp"))

Created on 2018-07-03 by the reprex package (v0.2.0).

chr1swallace commented 6 years ago

Thanks for checking! With https://github.com/chr1swallace/dotwhisker seems fixed:

image

fsolt commented 6 years ago

And your fix works:


library(dotwhisker)
#> Loading required package: ggplot2

m1 <- lm(mpg ~ wt + cyl + disp + gear, data = mtcars)
m2 <- update(m1, . ~ . + hp) # add another predictor
m3 <- update(m2, . ~ . + am) # and another 

dwplot(list(m1, m2, m3), order_vars = c("cyl", "disp", "gear", "wt", "am", "hp"))

Created on 2018-07-03 by the reprex package (v0.2.0).

fsolt commented 6 years ago

Thanks, Chris! I appreciate your help with this!