Using ggplot I'm trying to make something like a faceted barplot where
- bars representing the same value are the same size (sort of like
space = "free") - names are adjacent to bars (sort of like
scales = "free_y") - graphs are generated with code - no trial and error adjustment of size or scale or stuff
I'm open to a multi-plot solution with something like cowplot::plot_grid
Here's a sample dataset.
df <- data.frame(name = c('A very long name','A short name','A really truly long big name that is very long','One shorter name'),
value =c(100,50,10,10),
group = c(2022,2022,2022,2021))
What I'm aiming for would look something like this:
Two things I've tried and rejected:
ggplot(df,
aes(x = name, y = value)) +
geom_col(aes(fill = -value)) +
coord_flip() +
facet_grid(~group, space = "free", scales = "free_x") +
theme(legend.position = "none")
ggplot(df,
aes(x = name, y = value)) +
geom_col(aes(fill = -value)) +
coord_flip() +
facet_wrap(~group, scales = "free_y") +
theme(legend.position = "none")






