1

This is my first time posting a question here so I'm nervous, but this has been bugging me forever: when using facet_wrap() in ggplot, is there a way to keep your plots from getting all squished when you have a lot of them? (see example below)

squishy plots

There is too much range in the data so I have to free the scales, otherwise I would set the y-axis breaks and probably have fewer labels to that from crowding. But the biggest thing is that the plots are so squished they become hard to see. When I put space in between the plots it just squishes them more as though it is working with a limited amount of space. I also tried adjusting font sizes, getting rid of the title, and even the legend. Removing the legend makes more room but obviously, that's sort of an important thing to have in there!

Is there a way to fix this or is this just something that goes with trying to facet a lot of plots?

Here is my code:

  lu_acres_plot <- ggplot(data = land_use_acres, aes(x = land_use, y = acres)) +
  geom_col(aes(fill = land_use)) +
  facet_wrap(~i_desclu, scales = "free_y") +
  labs(title = "Land Use Change",
       y = "Change in Acreage") +
  theme_minimal() +
  geom_hline(aes(yintercept=0)) +
  scale_fill_manual(values = lu_pallette) +
  theme(
    axis.title.x = element_blank(),
    axis.text.x = element_blank(),
    text = element_text(family = "Times"),
    axis.text = element_text(size = 12),
    axis.title = element_text(size = 14, face = "bold"),
    plot.title = element_text(size = 16, face = "bold"),
    legend.position = "bottom",
    legend.title = element_text(size = 14, face = "bold"),
    legend.title.align = 0.5,
     strip.background = element_rect(color = "grey40", fill = "grey30"),
    strip.text = element_text(size = 9, color = "white", face = "bold"),
    panel.border = element_rect(color = "grey40", fill = NA)
   ) +
    guides(fill = guide_legend(title = "Land Use",
                               title.position = "top",
                               nrow = 2))
lu_acres_plot
Ben Bolker
  • 211,554
  • 25
  • 370
  • 453
mbouff
  • 11
  • 1
  • 3
    I'm not clear on how you want to make them less squished. What exactly do you want to change? You can always just make your plotting device taller so you have more room. It's not clear currently how you are saving this image. It's easier to help you if you include a simple [reproducible example](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) with sample input and desired output that can be used to test and verify possible solutions. – MrFlick Nov 30 '21 at 20:37
  • Mayeb [this SO post](https://stackoverflow.com/questions/36783189/changing-the-appearance-of-facet-labels-size) can help. – Rui Barradas Nov 30 '21 at 21:03
  • Try saving plot to a file and manually adjusting the plot dimensions. `ggsave("plot1.pdf", plot=lu_acres_plot, width=12, height=8)`. Change height and width until the pdf looks good to you. – bdemarest Dec 01 '21 at 00:48
  • @bdemarest thank you that worked beautifully! I never thought of changing the aspect ratio but that's the piece I've been missing! Thank you, this has bothered me for years! – mbouff Dec 01 '21 at 01:23
  • @RuiBarradas thank you that page is very helpful too! – mbouff Dec 01 '21 at 01:23

0 Answers0