[英]Annotate combined subplots (patchworks?) as single plots using patchwork
I'm trying to figure out how to annotate combined patchworks as if they were individual plots.我试图弄清楚如何注释组合拼凑而成,就好像它们是单独的情节一样。
I've got one patchwork consisting of three combined plots and another single plot.我有一个拼凑而成的三个组合图和另一个 plot。 The final composite plot is the first patchwork on top and the individual plot on the bottom.
最终的复合材料 plot 是顶部的第一个拼布,底部是单独的 plot。 I have no problem getting the layout I want, but when I use
plot_annotation
, it gives letters to every plot, whereas what I'd like to see is an A for the top plot (patchwork of three subplots) and a B for the bottom one (just a single plot)我得到我想要的布局没有问题,但是当我使用
plot_annotation
时,它给每个 plot 提供字母,而我想看到的是顶部 plot 的 A (三个子图的拼凑)和底部的 B一个(只是一个情节)
Here's what I'm currently doing:这是我目前正在做的事情:
library(ggplot2)
library(patchwork)
p1 <- ggplot(mtcars) +
geom_point(aes(mpg, disp)) +
ggtitle('Plot 1')
p2 <- ggplot(mtcars) +
geom_boxplot(aes(gear, disp, group = gear)) +
ggtitle('Plot 2')
p3 <- ggplot(mtcars) +
geom_point(aes(hp, wt, colour = mpg)) +
ggtitle('Plot 3')
p4 <- ggplot(mtcars) +
geom_bar(aes(gear)) +
facet_wrap(~cyl) +
ggtitle('Plot 4')
top_plot = (p1 + p2 + p3)
bottom_plot = p4
combined_plot <- (top_plot / bottom_plot) + plot_annotation(tag_levels="A")
combined_plot
What I'd like to see, rather than AD annotations, is A for the top plot (plots 1-3) and a B for the bottom one (plot 4).我希望看到的不是 AD 注释,而是顶部 plot(图 1-3)的 A 和底部的 B(图 4)。 Is there a way to do this?
有没有办法做到这一点?
One solution is to create two complete patchwork plots, each with its own annotation.一种解决方案是创建两个完整的拼凑图,每个图都有自己的注释。 You have to put them each inside
wrap_elements
to declare them as complete patchworks for this to work.您必须将它们分别放在
wrap_elements
中,以将它们声明为完整的拼凑物才能正常工作。 Thereafter you can combine them as you would combine ggplots:此后,您可以像组合 ggplots 一样组合它们:
top_plot <- wrap_elements((p1 + p2 + p3) + plot_annotation(title = "A"))
bottom_plot <- wrap_elements(p4 + plot_annotation(title = "B"))
combined_plot <- top_plot / bottom_plot
combined_plot
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.