简体   繁体   English

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

I've made a series of plots that I want to print on the same page.我制作了一系列要在同一页面上打印的图。

The main plot, dotplot_summary , is a summary of the plots in dotplots_indiv <- list(p1, p2, p3) .主要的 plot, dotplot_summarydotplots_indiv <- list(p1, p2, p3)中的图的摘要。

I'd like the first plot to be the same size as the plots on the second row, but I can't figure out how.我希望第一个 plot 的大小与第二行的图相同,但我不知道如何。

My reprex is here: https://pastebin.com/wjhmSFiB我的代表在这里: https://pastebin.com/wjhmSFiB

p_indiv <- wrap_plots(dotplots_indiv) 
patchwork <- (dotplot/p_indiv) + plot_layout(nrow = 2, widths = c(1, 3)

I was thinking of adding plot spacers, but the number of plots that can fit in the lower row is variable.我正在考虑添加 plot 垫片,但可以放在下排的地块数量是可变的。

Thanks.谢谢。

在此处输入图像描述

I was not able to reproduce the issue with the data you shared as it is giving errors but I sketched an example.我无法使用您共享的数据重现该问题,因为它给出了错误,但我画了一个示例。 You can use the layout option in wrap_plots() defining a matrix style like this (I have used iris data):您可以使用wrap_plots()中的layout选项定义这样的矩阵样式(我使用了iris数据):

library(patchwork)
library(ggplot2)
#Plot 1
G1 <- ggplot(iris,aes(x=Sepal.Length,y=Sepal.Width))+
  geom_point()
#Plot 2
G2 <- ggplot(iris,aes(y=Sepal.Length,x=Sepal.Width))+
  geom_point()
G3 <- ggplot(iris,aes(y=Petal.Width,x=Sepal.Width))+
  geom_point()
G4 <- ggplot(iris,aes(y=Petal.Length,x=Petal.Width))+
  geom_point()
#Wrap
#Layout
layout <- '
#A#
BCD
'
#Plot
wrap_plots(A = G1, B = G1,C=G2,D=G3, design = layout)

Output: Output:

在此处输入图像描述

All plots will keep same dimension, rather than this:所有地块都将保持相同的尺寸,而不是这样:

在此处输入图像描述

Which follows a code structure similar to the one you shared.它遵循与您共享的代码结构相似的代码结构。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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