Home > Software design >  How to center ggplot figure in R
How to center ggplot figure in R

Time:12-01

Is there a way to center the "Open Tray" figure in the bottom row?

I am trying to use sfplot <- ggarrange(Cf, Ff, Of, labels = c("A", "B", "C")), but obviously it won't automatically center it. Thanks in advance!

image

CodePudding user response:

With the patchwork package, you could use:

library(patchwork)
a <- ggplot(mtcars, aes(disp, wt))   geom_point()
a   a   a   
  plot_annotation(tag_levels = 'A')  
  plot_layout(
  design = "AABB
            #CC#") 

enter image description here

CodePudding user response:

If you wanted to use ggarrange, then you can nest each row of plots within another ggarrange (though this is obviously more verbose than just using patchwork):

library(ggpubr)
library(ggplot2)

Cf <- Ff <- Of <- ggplot(mtcars, aes(disp, wt))   geom_point()

sfplot = ggarrange(ggarrange(Cf, Ff, ncol = 2, labels = c("A", "B")), 
                   ggarrange(NULL, Of, NULL, ncol = 3, labels = c("", "C", ""), widths = c(1,2,1)), 
                   ncol = 1)

Output

enter image description here

  • Related