ggh4x how to stretch strip across layers
06:07 03 Dec 2025

I'm working on a facet_nested_wrap plot (see image below) where I happen to have one of the aspect (CENT) having only one level, as opposed to two, as in the other (TELO).

img

Is there a way to increase the height/stretch that strip so that it has the same height of those in the other facet combined? I share a head() and tail() of the df, but basically for the variable ARM the CENT category has NA.

head(all)

  HAP   CHR   `Length (in bps)` REG   ARM  
                  
1 hap1  chr1               4535 TELO  p-arm
2 hap1  chr1               4435 TELO  p-arm
3 hap1  chr1               4335 TELO  p-arm
4 hap1  chr1               4235 TELO  p-arm
5 hap1  chr1               4135 TELO  p-arm
6 hap1  chr1               4035 TELO  p-arm

tail(all)

HAP   CHR   `Length (in bps)` REG   ARM  
                  
1 hap1  chr21           1761195 CENT  NA   
2 hap2  chr21           2093093 CENT  NA   
3 hap1  chr22           3272138 CENT  NA   
4 hap2  chr22           4103205 CENT  NA   
5 hap1  chrX            4394450 CENT  NA   
6 hap2  chrX            2887908 CENT  NA

So, far what I attained with my code was to only suppress the bottom layer with element_blank(); however, I couldn't figure out how to selectively control strips height. Any help is much appreciated, thanks!

CODE

library(ggh4x)
library(scales)
library(ggplot2)
library(extrafont)
library(paletteer)
library(elementalist)

t_col <- function(color, percent = 75, name = NULL) {
  rgb.val <- col2rgb(color)
  
  t.col <- rgb(rgb.val[1], rgb.val[2], rgb.val[3],
               max = 255,
               alpha = (100 - percent) * 255 / 100,
               names = name)
  
  invisible(t.col)
}
legend_fill <- t_col("white", perc=25, name="lt.fill")
fancy_scientific <- function(l) {
  l <- format(l, scientific = TRUE)
  l <- gsub("^(.*)e", "'\\1'e", l)
  l <- gsub("e", "%*%10^", l)
  parse(text=l)
}

strips_2 <- strip_nested(
  
  background_y = list(element_rect(fill="#8e9295"),
                      element_rect(fill="#8e9295"),
                      element_blank(),
                      element_rect(fill="#2a52be"),
                      element_rect("#4169e1")),
  text_y = list(element_text(face="bold", color="white", size=12),
                element_text(face="bold", color="white", size=12),
                element_blank(),
                element_text(color="white", size=10),
                element_text(color="white", size=10)),
  by_layer_y = FALSE
  
)

my_palette <- paletteer_d("wesanderson::Darjeeling1")[c(2,4)]

facet_both <- ggplot(all, aes(fill=HAP, x=CHR, y=`Length (in bps)`)) +
  geom_col(position="dodge", width=.4, alpha=.75, color="black", linewidth=0.1) +
  theme_bw() + facet_nested_wrap(~REG + ARM, ncol=1, dir="h", strip=strips_2, strip.position="left", scales="free_y") +
  theme(legend.box.background=element_rect_round(color="black", 
                                                 fill=legend_fill, 
                                                 linetype="solid", 
                                                 radius=unit(1,"mm")),
        legend.background=element_rect(fill="transparent"), 
        legend.position.inside=c(0.951,0.94), legend.box='horizontal',
        text=element_text(family="Arial"), panel.grid=element_blank(), legend.title=element_blank(), 
        axis.text=element_text(size=12), axis.text.x=element_text(angle=45, hjust = 1), axis.title.x=element_blank(), 
        axis.title.y=element_text(size=16), legend.text=element_text(size=8), plot.margin=unit(c(.3, .5, .2, .2), "cm"), 
        panel.border = element_rect(colour="black", fill=NA, linewidth=1.5)
  ) +
  guides(fill=guide_legend(ncol=2, keywidth=1, position="inside")) + scale_fill_manual(values=(my_palette)) +
  scale_y_continuous(labels=function(x) ifelse(x == 0, "0", fancy_scientific(x)), limits=c(0, NA), expand=c(0, 0), position="right")
facet_both + facetted_pos_scales(
  y = list(
    REG == "CENT" ~ scale_y_continuous(labels=function(x) ifelse(x == 0, "0", fancy_scientific(x)), limits=c(0, 1.5e+07), expand=c(0, 0), position="right"),
    REG == "TELO" ~ scale_y_continuous(labels=function(x) ifelse(x == 0, "0", fancy_scientific(x)), limits=c(0, 25000), expand=c(0, 0), position="right", 
                                       breaks=c(0, 8000, 16000, 24000))
  )
)
r ggplot2 facet ggh4x