fsolt/dotwhisker

add_brackets includes rect when xmax is large

Opened this issue · 0 comments

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)