fsolt/dotwhisker

ordering doesn't work with more than one regression

chr1swallace opened this issue · 4 comments

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

df <- df[match(order_vars, df$term),] %>% stats::na.omit()

I think this is fixed by replacing the line with

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

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).

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

image

fsolt commented

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

Thanks, Chris! I appreciate your help with this!