I tried to align to plot one on top of the other with ggplot2. Data in two plots show each category of x property.
Here you can download the sample data: https://gist.github.com/itsvenu/97605e07b626d04f290fb39af7ccbc3a
Following is the code I wrote to produce the figure
all_sb <- unique(mp_mb_sampledata$SB) 
cl_min <- seq(from = 0.5, to = max(as.numeric(as.factor(all_sb))), by = 1)[1:length(all_sb)]
cl_max <- seq(from = 1.5, to = max(as.numeric(as.factor(all_sb))) + 0.5, by = 1)[1:length(all_sb)]
shading_cols <- data.frame(min = cl_min,
                           max = cl_max,
                           col = rep(c(0, 1), length(cl_min)))
## top panel
p1 <- ggplot()+
  ggbeeswarm::geom_quasirandom(data = mp_mb_sampledata, aes(x = SB, y = mut_per_mb))+
  geom_rect(data = shading_cols,
            aes(xmin = min, xmax = max, ymin = -Inf, ymax = Inf,
                fill = factor(col), alpha = 0.01))+
  scale_fill_manual(values = c("white", "gray"), guide = FALSE)+
  ggbeeswarm::geom_quasirandom(data = mp_mb_sampledata, aes(x = SB, y = mut_per_mb))+
  coord_trans(y="log2")+
  theme_classic(base_size = 18)+
  xlab("")+ylab("")+
  theme(legend.position = "none",
        axis.text.x = element_blank(),
        axis.ticks.x = element_blank(),
        axis.line.x = element_blank(),
        axis.text = element_text(color = "black"))
## bottom panel
p2 <- ggplot()+
  geom_bar(data = req_bc, aes(x = SB, y = Freq, fill = MutationType), stat = "identity")+
  geom_rect(data = shading_cols,
            aes(xmin = min, xmax = max, ymin = -Inf, ymax = Inf,
                fill = factor(col), alpha = 0.01))+
  scale_fill_manual(values = color_pal)+
  geom_bar(data = req_bc, aes(x = SB, y = Freq, fill = MutationType), stat = "identity")+
  theme_classic(base_size = 18)+
  theme(axis.text = element_text(color = "black"),
        plot.margin = unit(c(0.01, 5.5, 5.5, 5.5), "pt"))+
  ylab("Fraction")+
  scale_y_continuous(breaks = c(0, 0.50, 1), labels = c(0, 0.50, 1))+
  ggpubr::rotate_x_text(angle = 90, hjust = 1)
## both in one
p1 + p2 + patchwork::plot_layout(ncol = 1)
That produced

I would like to arrange the top and bottom panel shadings on the same lines. For some reason, there coming a space between y axis and first beeswarm dots. I tried expand argument, but it didn't change anything.
Any help would be greatly appreciated.
Thank you.
