简体   繁体   English

如何在 R 中居中 ggplot 图

[英]How to center ggplot figure in R

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.我正在尝试使用sfplot <- ggarrange(Cf, Ff, Of, labels = c("A", "B", "C")) ,但显然它不会自动居中。 Thanks in advance!提前致谢!

图片

With the patchwork package, you could use:使用patchwork而成的 package,您可以使用:

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

在此处输入图像描述

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 ):如果你想使用ggarrange ,那么你可以将每一行图嵌套在另一个ggarrange (尽管这显然比只使用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 Output

在此处输入图像描述

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM