当地块纵横比为1时,将地块与拼凑而成

我遇到了使用patchworkwhen组合图的问题theme(aspect.ratio = 1)。提供了一些示例:

library(tidyverse)
library(patchwork)

# Create the base plots
plotlist = list(
  fig1 = iris %>% 
    filter(Species == "setosa") %>% 
    ggplot(aes(x = Sepal.Length, y = Sepal.Width)) +
    geom_point(),
  
  fig2 = iris %>% 
    filter(Species == "versicolor") %>% 
    ggplot(aes(x = Sepal.Length, y = Sepal.Width)) +
    geom_point(),
  
  fig3 = iris %>% 
    filter(Species == "virginica") %>% 
    ggplot(aes(x = Sepal.Length, y = Sepal.Width)) +
    geom_point()
)

# Here patchwork combines the plots nicely
plotlist$fig1 / (plotlist$fig2 + plotlist$fig3)

# However, if we change the aspect.ratio to 1 things don't look so nice anymore
plotlist = lapply(plotlist, function(x) {
  x + theme(aspect.ratio = 1)
})

# Notice the large gap between plots. Instead, I would like the plots in the second row to be almost directly under the first row.
plotlist$fig1 / (plotlist$fig2 + plotlist$fig3)
# I tried setting the margins to zero, but that doesn't change anything
plotlist = lapply(plotlist, function(x) {
  x + theme(plot.margin = margin(0, 0, 0, 0, unit = "pt"))
})

plotlist$fig1 / (plotlist$fig2 + plotlist$fig3)

如何使用拼凑来改进布局?第二行中的图应该像第一行一样具有第一行的一半宽度,但所有图的纵横比都应为 1。

以上是当地块纵横比为1时,将地块与拼凑而成的全部内容。
THE END
分享
二维码
< <上一篇
下一篇>>