oma equivalent in ggarrange?

205 views
Skip to first unread message

Karl Fetter

unread,
Sep 7, 2017, 7:22:59 PM9/7/17
to ggplot2
Hello, I have a panel of 9 figures arranged in a 3 x 3 grid. I want to add extra space to the top of the plotting area so I can add a few annotations above the columns. In base graphics I would set the outer margins to give me more space using par(oma=c(0,0,5,0), mfrow=c(3,3)), and then add the plots and go to town. Setting the plot parameters with par doesn't work with ggplots, so is there an equivalent to oma for ggplots or ggpubr's ggarrange?

Thanks for the help, sorry if this is a basic question and my googling just didn't uncover the answer.

Theo Mouton

unread,
Sep 7, 2017, 7:29:45 PM9/7/17
to Karl Fetter, ggplot2

With p1, p2, and p3 being three ggplots, you can try using grid.arrange() this way:

 

left=textGrob("", gp = gpar(fontface = "bold", cex=1.2), rot = 90)

bottom=textGrob("", gp = gpar(fontface = "bold", cex=1.2), hjust=-0.4)

top=textGrob("", gp = gpar(fontface = "bold", cex=1.2))

 

P1<-arrangeGrob(p1, top = textGrob("(A)", x = unit(0.17, "npc"), y= unit(0.3, "npc"), just=c("left","top"), gp=gpar(col="black", fontsize=12, fontface="bold", fontfamily="Times Roman")))

P2<-arrangeGrob(p2, top = textGrob("(B)", x = unit(0.17, "npc"), y= unit(0.3, "npc"), just=c("left","top"), gp=gpar(col="black", fontsize=12, fontface="bold", fontfamily="Times Roman")))

P3<-arrangeGrob(p3, top = textGrob("(C)", x = unit(0.17, "npc"), y= unit(0.3, "npc"), just=c("left","top"), gp=gpar(col="black", fontsize=12, fontface="bold", fontfamily="Times Roman")))

 

grid.arrange(P1, P2, P3, ncol=2, bottom=bottom, left=left, top=top)

 

There is also plot_grid(), which less flexible but much faster to use, example:

plot_grid(g3, g5, labels=c("(A)", "(B)"), ncol =1 , nrow =1)

--
--
You received this message because you are subscribed to the ggplot2 mailing list.
Please provide a reproducible example: https://github.com/hadley/devtools/wiki/Reproducibility
 
To post: email ggp...@googlegroups.com
To unsubscribe: email ggplot2+u...@googlegroups.com
More options: http://groups.google.com/group/ggplot2

---
You received this message because you are subscribed to the Google Groups "ggplot2" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ggplot2+u...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Theo Mouton
Freshwater Research Assistant
+64-7-859-1889 | Gate 10 Silverdale Road, Hillcrest, Hamilton | www.niwa.co.nz
NIWA
To ensure compliance with legal requirements and to maintain cyber security standards, NIWA's IT systems are subject to ongoing monitoring, activity logging and auditing. This monitoring and auditing service may be provided by third parties. Such third parties can access information transmitted to, processed by and stored on NIWA's IT systems.



Reply all
Reply to author
Forward
0 new messages