简体   繁体   中英

R ggplot2 facet_wrap: how to create different number of columns in different rows

I have 14 groups total, i want to present 4 columns in the first row, 5 in the 2nd and 3rd row.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)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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