是否有一种方法可以压缩使用facet_wrap的ggplot?这是我要压缩的情节示例。理想情况下,最左边的地块(年龄类别)应有更大的间距,而其余的地块则更为紧凑。
这是一个玩具示例。理想情况下,中间图将更窄。
mtcars %>%
mutate(cylinders = case_when(cyl == 4 ~ "Four cyl",
cyl == 6 ~ "Six cyl",
cyl == 8 ~ "Eight cyl"),
cylinders = reorder(cylinders, cyl, mean)) %>%
mutate(engine = case_when(vs == 1 ~ "Manual",
vs == 0 ~ "Automatic")) %>%
mutate(gears = case_when(gear == 3 ~ "Three",
gear == 4 ~ "Four",
gear == 5 ~ "Five"),
gears = reorder(gears, gear, mean)) %>%
select(cylinders, engine, gears) %>%
gather(key, value) %>%
count(key, value) %>%
ggplot(aes(x = value, y = n)) +
geom_bar(stat = "identity", width = 0.3) +
facet_wrap(~ key, scales = "free_x", ncol = 3)