简体   繁体   English

使用拼凑将组合子图(拼凑?)注释为单个图

[英]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.

相关问题 将单个组合的 x 轴标题添加到 2 个拼凑图 - Add single combined x-axis title to 2 patchwork plots 拼凑不会为组合图分配公共图例 - Patchwork won't assign common legend for combined plots 通过迭代 for 循环创建单个图,将图拼凑在一起 - Putting together a patchwork of plots by creating single plots by iterating over a for loop 使用拼凑时如何减少绘图之间的空间 - How to reduce the space between to plots when using patchwork 使用拼凑来组织两个不同宽度和高度的地块 - Using patchwork to organise two plots with different widths and heights 使用r中的子图显示带有几何点和单个图例的两个条形图 - Show two bar plots with geom points and single legend using subplots in r patchwork::plot_layout: 一个 plot 在顶行,然后在后续行中可变数量的地块,但所有地块保持相同的宽度 - patchwork::plot_layout: one single plot on top row, then variable number of plots in subsequent rows, but keep same width for all plots 控制使用拼凑创建的子图的大小 - 代码改进 - Control size of subplots created with patchwork - code improvement 从 ggplots 列表中自动组装拼凑图 - Automatically assemble plots for patchwork from a list of ggplots 使用 flexdashboard、lapply 和拼凑而成的动态绘图数 - Dynamic number of plots with flexdashboard, lapply and patchwork
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM