2

I have a plot using doubly nested facets in ggh4x. I would like to have horizontal lines inside the plot separating only the outer facets.

library(data.table)
library(ggh4x)

DT <- data.table(feature = rep(c("var1","var2"),each=9),
                 ord = rep(c(1,2),each=9),
                 fold = c(1,2,3,5,1,2,3,4,5,1,2,3,5,1,2,3,4,5),
                 navn = c(rep("A",4),rep("B",5),rep("A",4),rep("B",5)))

ggplot(DT) + 
  geom_rect(aes(fill = navn),xmin = -Inf,xmax = Inf,
            ymin = -Inf,ymax = Inf) +
  facet_nested(feature + fold ~ ord + navn, scales = "free",
               space = "free_y",
               nest_line = TRUE) +
  theme_minimal() +
  theme(strip.text.y.right = element_text(angle = 0),
        text = element_text(size=20),
        ggh4x.facet.nestline = element_line(linetype = 3)) +
  guides(fill=guide_legend(title=" "))

double_nested_facet_plot

So, in the plot above, I would like to add a horizontal line in between var1 and var2 without adding horizontal lines to each of the inner facets. I have tried various iterations of theme(panel.border...) and annotation lines (such as in this stack overflow post) but have been unable to find a solution that works with only the outer facet in a nested facet setup.

Any help with this would be greatly appreciated!

danibarna
  • 21
  • 2

0 Answers0