0

Is there a way to condense a ggplot that uses facet_wrap? Here's an example of a plot I'm trying to condense. Ideally, the far left plot (age categories) would be spaced out more, while the remaining plots would be more condensed. enter image description here

Here's a toy example. Ideally, the middle plot would be narrower.

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)

enter image description here

Daniel
  • 415
  • 1
  • 6
  • 16

0 Answers0