我怎样才能附加小平面并在图中保持单个小平面高度不变?

How can I append facets and keep individual facet height in the plot as is?

我想用 ggplot2 创建一个大的 facet_wrap

我想要的是一些自动方法来按列附加各个方面,以便如果(使用相同的数据)只有将提供具有四列分面的第一行。

例如我担心地块高度。我知道如何手动更改地块高度,但我需要一种自动方式。

一些示例数据:

mpg <- mpg %>%
distinct(model, year, .keep_all = TRUE)

ggplot(mpg, aes(x=year, y=hwy))+
   geom_point()+
   facet_wrap(~model)

所有面的高度应与

相同
mpg %>%
  distinct(model, year, .keep_all = TRUE) %>%
  filter(model %in% c("4runner 4wd", "a4", "a4 quattro", "altima")) %>%

  ggplot(aes(x=year, y=hwy))+
  geom_point()+
  facet_wrap(~model, ncol = 4)

您可以使用 theme(aspect.ratio) 来节省地块高度。例如,

mpg <- mpg %>%
    distinct(model, year, .keep_all = TRUE)

ggplot(mpg, aes(x=year, y=hwy))+
    geom_point()+
    facet_wrap(~model) + theme(aspect.ratio=2)