GGnested plot with customization on position for strip text

29 Views Asked by At

Based on these I tried to reproduce some of these graphics using the original code on ggnested, for some additional customization features.

That said, when I made my plot, for some reason I have a gap between my strip text above my relative abundance stacked bars, which is a bit annoying. There is also a space in the bottom of the graph. It looks like the background is not strictly adapted to my y-axis length. Anyone around using this package ggnested and could have an idea of what I should do ?

Thanks in advance the community !

I tried strip.placement = "outside" and "inside" or plot.margin = 0,0,0,0 but nothing worked.

My code:

ggnested(melt(...))+
  labs(title = "Phyla and their Top5 Families distribution", 
       x = "")+  
  theme(
    panel.background = element_blank(),
    axis.ticks.x = element_blank(),
    axis.text.x = element_blank(),
    strip.background = element_rect(fill = "lightgrey"),
    strip.text = element_text(color = "black", size = 9, face = "bold"),
    legend.key.size = unit(0.5, "cm"),
    strip.placement = "outside",
    plot.margin = margin(0, 0, 0, 0, unit = "cm")
  )

enter image description here

1

There are 1 best solutions below

0
gmt On

I'm the author of ggnested. The extra space is ggplot's default; you can remove it using the code below.

ggnested(melt(...)) +
scale_y_continuous(expand = c(0,0)) +
...