以grid.arrange排列的标签图

问题描述 投票:0回答:1

我已使用grid.arrange将多个绘图附加到一页上。

是否有一种方法可以用“(a)”,“(b)”等标记每个图...

我尝试使用geom_text,但它似乎与我的绘图不兼容。...

my plots

....如您所见,geom_text与我的图例符号有一些奇怪的交互。

我将显示一个使用mtcars数据的示例,以说明我要实现的目标。我发现的geom_text替代品是“注释”,它不会与图例符号交互。但是,仅标记一个面并不容易。...

q1=ggplot(mtcars, aes(x=mpg, y=wt)) + 
geom_line() +
geom_point()+
facet_grid(~cyl)+
annotate(geom="text", x=15, y=12, label="(a)",size=8,family="serif")

q2=ggplot(mtcars, aes(x=mpg, y=wt,)) + 
geom_line() +
geom_point()+
facet_grid(~cyl)+
annotate(geom="text", x=15, y=12, label="(b)",size=8,family="serif")


geom_text(x=15, y=5,size=8, label="(b)")

gt1 <- ggplotGrob(q1)
gt2 <- ggplotGrob(q2)


grid.arrange(gt1,gt2, ncol=1)

mtcars example

因此,我的问题是,有没有一种方法可以标记使用grid.arrange排列的图,以便每个图的第一个小平面都用a或b或c等标记??

r ggplot2 label linegraph facet-grid
1个回答
0
投票
您可以使用ggarrange包中的ggpubr,并使用参数labels为每个图设置标签:

library(ggplot2) library(ggpubr) q1=ggplot(mtcars, aes(x=mpg, y=wt)) + geom_line() + geom_point()+ facet_grid(~cyl)+ annotate(geom="text", x=15, y=12, label="(a)",size=8,family="serif") q2=ggplot(mtcars, aes(x=mpg, y=wt,)) + geom_line() + geom_point()+ facet_grid(~cyl)+ annotate(geom="text", x=15, y=12, label="(b)",size=8,family="serif") ggarrange(q1,q2, ncol = 1, labels = c("a)","b)"))

enter image description here

这是您要寻找的吗?

© www.soinside.com 2019 - 2024. All rights reserved.