1

I had trouble trying to remove the vertical white space between each plot. I have several plots so I used ggarrange to combine them.

This is my code:

figure <- ggarrange(lima_exceso,loreto_exceso,amazonas_exceso,madre_exceso, 
                    callao_exceso,apurimac_exceso,ancash_exceso, 
                    sanmartin_exceso, ica_exceso,ayacucho_exceso, 
                    arequipa_exceso, piura_exceso,junin_exceso,pasco_exceso, 
                    cusco_exceso,lambayeque_exceso,huancavelica_exceso,
                    puno_exceso,tumbes_exceso,lalibertad_exceso,                       
                    tacna_exceso,huanuco_exceso,cajamarca_exceso,
                    labels = c(""), 
                    ncol = 4, nrow = 6)



annotate_figure(figure,
                top = text_grob("Exceso de fallecidos  (media móvil-7d)",
                color = "black", face = "bold", size = 12),
                bottom = text_grob("Data source: \n  Minsa ", 
                color = "black", hjust = 0, x = 0, face = "italic",
                size = 8), fig.lab = "", fig.lab.face = "bold", 
                fig.lab.pos = "top.right"  , fig.lab.size = 8)


ggsave(file="ex31.pdf" , height = 350, units = "mm" , width =  340)

This is the outcome:

enter image description here

As you can see there is a lot of vertical space between the graphics and that's why the title is too close from the plots. The margin of the pdf is tiny.

So I tried to narrow that space by setting margins for each plot (just for the first column), however, the outcome was not what I wanted.

I add this line code to the plots of the first column:

+theme(plot.margin = unit(c(-0.25,0.5,-0.25,0.5), "lines"))

This was the outcome:

enter image description here

As you can see I narrowed the vertical space but now the plots of the first column are taller than the others, and the title of the first plot (right corner) is too close from the ggarrange title. I want to reduce the space between the plots but I don't want to modify anything else.

Is there a way to reduce the vertical space of my plots using ggarrange?

tamtam
  • 3,541
  • 1
  • 7
  • 21
Jose Montoya
  • 147
  • 1
  • 10

0 Answers0