Search code examples
rggplot2patchwork

Unwanted separation marks / lines between assembled ggplots using {patchwork}


I'm trying to combine plots with "grey20" as the plot background. However, while combining plots, an unwanted behavior seems to be happening as a lighter separation line appears between the top plot and the bottom plots.

Does someone know whether this comes from a mistake on my part, or whether there is a workaround to avoid this unpleasant behavior ?

Thank you very much for your help !

Best,

# plotA

plotA <- plot_spacer()+ theme(plot.background = element_rect(fill = "grey20",color = "grey20"))

  
# plotB

plotB <- plot_spacer()+ theme(plot.background = element_rect(fill = "grey20",color = "grey20"))
  
  
# plotC
  
plotC <- plot_spacer()+ theme(plot.background = element_rect(fill = "grey20",color = "grey20"))
                              
# Combining plots

(plotA / (plotB + plotC )) + plot_layout(heights = c(1,.1))

Edit - Although it does seem that the issue came from my specific graphic device setup as this problem did not occur while using R directly (instead of RStudio), the issue was corrected anyway with the following added element piece of code :


((plotA / (plotB + plotC )) + plot_layout(heights = c(1,.1))) & theme(plot.background = element_rect(fill = "grey20",color = "grey20")


Solution

  • Edit -

    Thank you all for your answers, the situation is now solved !

    I understand three things from this situation :

    1. The graphic device setup can have an influence on the end result (this problem did not occur when I was using R directly instead of RStudio)

    2. The heights argument seems to be the cause of the situation

    3. Either way, adding the following piece of code solves it all (here, specifying that the plot background for all three patchworked should be colored and filled the way each individual plot is) :

    ((plotA / (plotB + plotC )) + plot_layout(heights = c(1,.1))) & theme(plot.background = element_rect(fill = "grey20",color = "grey20")
    
    

    Best,

    Henri