fsolt / dotwhisker

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

add_brackets includes rect when xmax is large #90

Open judgelord opened 5 years ago

judgelord commented 5 years ago

I did not expect a rect geom added to a dwplot to appear under the brackets as well. This is not a big problem, just unexpected. Perhaps we just need to avoid relatively large values with add_brackets. In this example, any value over ~145 appears under the brackets.

My aim was to distinguish among terms with multiple models by including a rect under every other term. This could even be a nice feature if it does not exist.

library(broom)
library(dplyr)
data(mtcars)
m1 <- lm(mpg ~ wt + cyl + disp, data = mtcars) %>% 
  tidy()
two_brackets <- list(c("Engine", "Cylinder", "Displacement"),
                     c("Not Engine", "Intercept", "Weight"))

{dwplot(m1, show_intercept = T) %>%
    relabel_predictors("(Intercept)" = "Intercept",
                       wt = "Weight",
                       cyl = "Cylinder",
                       disp = "Displacement") +
    ggplot2::annotate(ymin = seq(.5,length(unique(m1$term)), 2), ymax = seq(1.5,length(unique(m1$term))+1, 2), 
             xmin = -Inf, xmax = Inf, 
             geom = "rect", alpha = 0.1) } %>%
  add_brackets(two_brackets)