1

I have a number of facets with uneven numbers of items in each. Something like this:

library(tidyverse)

mtcars %>%
  rownames_to_column("carmodel") %>%
  ggplot(aes(x = carmodel, y = mpg)) +
  geom_col() +
  facet_grid(cyl~., scales="free_y") +
  coord_flip()

enter image description here

As you can see, I'm basically using the facets as a grouping tool to organise similar observations together. The problem is, since the facets are evenly sized, some observations are getting much more screen real estate than others. (In my actual data, there are some groups with six and some with one, which means the data point in the "one" facet winds up very large.)

Instead of the default, I would instead like to resize the facets so that the observations (i.e. each car in the above) get the same amount of the chart space, i.e. spreading out the 8 cylinder cars and compressing the 6 cylinder cars. Is this possible?

Note: In case it makes a difference, in my actual code, I have both horizontal and vertical facets. The columns (y variable, since I've done the coord_flip()) should stay evenly spaced, I just want to resize the rows (x direction).

Z.Lin
  • 28,055
  • 6
  • 54
  • 94
Margaret
  • 5,749
  • 20
  • 56
  • 72

0 Answers0