r ggplot2 facet_wrap:如何在不同行中创建不同数量的列

发布于 2025-02-13 02:07:11 字数 109 浏览 2 评论 0原文

我总共有14个组,我想在第一行中介绍4列,第二行和第三行中有5列。 “

I have 14 groups total, i want to present 4 columns in the first row, 5 in the 2nd and 3rd row.
1

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

原谅我要高飞 2025-02-20 02:07:11

如评论中所述,您可以使用软件包ggh4x可以在其中创建自己的布局。我建议您查看评论中提到的链接,但我可以在您想要的布局中给您一个示例。重要的是在设计中#表示空单元。您可以对任何需要进行布局:

df <- data.frame(x = sample(1:14, 14),
                 y = sample(1:14, 14),
                 group = LETTERS[1:14])
design <- "
  ABCD#
  EFGHI
  #JKL#
"
library(ggplot2)
library(ggh4x)
p <- ggplot(df, aes(x = x, y = y)) + geom_point()
p + facet_manual(vars(group), design = design)
#> Warning: Found more facetting levels than designed. The following levels are
#> dropped: M, N

“”

在2022-07-05创建的 reprex软件包 (v2.0.1)

As said in the comments you can use the package ggh4x where you can create your own layout. I would suggest having a look at the link mentioned in the comments, but I can give you an example where you have the layout you want. The important part is in the design where # means empty cell. You can make a layout to whatever you want:

df <- data.frame(x = sample(1:14, 14),
                 y = sample(1:14, 14),
                 group = LETTERS[1:14])
design <- "
  ABCD#
  EFGHI
  #JKL#
"
library(ggplot2)
library(ggh4x)
p <- ggplot(df, aes(x = x, y = y)) + geom_point()
p + facet_manual(vars(group), design = design)
#> Warning: Found more facetting levels than designed. The following levels are
#> dropped: M, N

Created on 2022-07-05 by the reprex package (v2.0.1)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文