teunbrand/ggh4x

Vertical lines between strips (Feature request)

Closed this issue · 1 comments

I used the facet_nested_wrap to merge strips as you see in the image below. The thing is, the difference between strips could be not seen easily so I tried to add a vertical line between them but I didn't find a way to do it. I thought this would be a good feature for the gg4hx package.

This could be implemented as vline_between_strips like the already implemented nest_line.

In the image below I show the desired output through red vertical lines.

image

code:

library(tidyverse)
library(gg4x)

tibble(
  ffvv = sample(c("ffvv1", "ffvv2", "ffvv3", "ffvv4"), 20, TRUE),
  estudio = sample(c("esta", "estb", "estc"), 20, TRUE),
  epoca = sample(c("EH", "ES"), size = 20, replace = TRUE),
  riqueza = rnorm(20) %>% abs() %>% `*`(10)
) %>% 
  group_by(ffvv, estudio, epoca) %>% 
  summarise(n = sum(riqueza), .groups = "drop") %>% 
  ggplot(aes(epoca, n)) +
  geom_col() +
  ggh4x::facet_nested_wrap(~ffvv + estudio, nrow = 1, strip.position = "bottom", nest_line = element_line(linetype = 2), ) +
  #facet_grid(cols = vars(ffvv, estudio), switch = "x", labeller = label_wrap_gen(multi_line=FALSE)) +
  theme(strip.background = element_rect(fill = "white", color = "white"),
        strip.placement = "outside") +
  labs(x = NULL)

I kind of like this idea and I do see the utility of it. I have tried tinkering around with this and found that there isn't a clean way (that I could see) to implement this with the way the code currently works, so it would require a substantial re-write. Mostly the issue is that the strips are linked to panels and drawing lines in between panels isn't that straightforward, because there may or may not be just panel spacing or also axes in between panels, which makes it less predictable. I'm afraid that I'll have to conclude that I won't be planning to implement this feature, but do want to thank you for suggesting it and preparing a reproducible example.