fsolt / dotwhisker

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

add_brackets results in inconsistent brackets in dwplot #77

Closed svmiller closed 6 years ago

svmiller commented 6 years ago

Hi all,

I don't know when the next update of dwplot comes around but I hope a more consistent bracketing feature from the add_brackets function will be part of it.

I mentioned this on my Twitter but I think even the sample from the vignette illustrates the problem.

Notice how the "Overall" bracket does not fully include the "weight" category. The middle "Engine" bracket does include all relevant predictors in a way that's immediately obvious to the reader but the bracket for the "Transmission" category partially excludes the "Manual" predictor.

I'm having a similar issue in my own model where the bottom-most predictor, a single cross-level interaction in my model, is entirely excluded from the bracket that's supposed to cover it. Compounding matters, a previous compile of the exact same code resulted in a perfectly drawn set of brackets and I don't know what happened (some update of relevant packages?) that results in the discrepancy.

I appreciate your time.

fsolt commented 6 years ago

Blech--sorry about that Steven! Yep, that does stab the eyes. Something upstream must have broken it. I'm not sure how soon we'll be able to work on this, but we definitely will get it figured out eventually.

svmiller commented 6 years ago

No worries, and I assumed it was something upstream. I appreciate it all the same.

sammo3182 commented 6 years ago

The brackets only appear correctly with theme_bw. The brackets disappear w/o theme_bw.

three_brackets <- list(c("Overall", "Weight", "Weight"), 
                       c("Engine", "Cylinders", "Horsepower"),
                       c("Transmission", "Gears", "Manual"))

{dwplot(list(m1, m2, m3)) %>% 
    relabel_predictors(c(wt = "Weight",                       # relabel predictors
                         cyl = "Cylinders", 
                         disp = "Displacement", 
                         hp = "Horsepower", 
                         gear = "Gears", 
                         am = "Manual")) +
    xlab("Coefficient Estimate") + ylab("") +
    geom_vline(xintercept = 0, colour = "grey60", linetype = 2) +
    ggtitle("Predicting Gas Mileage") +
    theme(plot.title = element_text(face="bold"),
          legend.position = c(0.993, 0.99),
          legend.justification=c(1, 1),
          legend.background = element_rect(colour="grey80"),
          legend.title = element_blank())} %>% 
    add_brackets(three_brackets)
fsolt commented 6 years ago

Whaaaa? I confess I didn't believe this and had to confirm it myself, but you're right: also true for example for add_brackets(). That is super weird.