简体   繁体   中英

How to adjust margin in ggarrange ggpubr ggplot (axis elements disappear) R

I want to stack 3 plots into 1 using ggarrange but the x-axis elements (dates) of the bottom plot are always disappeared.

For example, here axis elements of plot_3 (Z) are missing.

ggarrange(plot_1, plot_2, plot_3 + rremove("x.text"), 
          nrow = 3, align = "h")

结果 1

And when I change the order, axis elements of plot_2 (Y) are now disappeared.

ggarrange(plot_1, plot_3, plot_2 + rremove("x.text"), 
          nrow = 3, align = "h")

结果 2

I tried to adjust the margins in each ggplot , but the same problem persists. So, I guess it must be something to do with the margins in ggarrange .

By the way, I also tried to remove all the x-axis title of the first two plots, and keep the title of the last (bottom) plot, but again, the dates are still missing.

I think that the function theme() would be useful

ggarrange(plot_1, plot_2, plot_3 + rremove("x.text"), 
          nrow = 3, align = "h")+
  theme(plot.margin = margin(0.1,0.1,2,0.1, "cm")) 

 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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