I am attempting to make lots of "small multiples" plots.
(Aside/Background) I have too many facets to display in a single plot so I need to manually subset them up into separate plots. I was hoping I could just pass the desired ncol and nrow to facet_wrap and it would make as many as I needed. That is not the case.
Because I have so many facets, space is at a premium. So, I wanted to reduce the size of the facet labels. Easy enough to reduce the strip.text font size, but sadly the strip.background rectangle does not size with the font nor does it provide sizing parameters (apart from border size). Setting it to element_blank() doesn't actually remove the space that is set aside for it, it just makes the same space transparent.
MWE:
set.seed(1)
xcat = rep(1:10, 1000)
yvalue1 = rep(runif(10,5,7),1000)
yvalue2 = rep(runif(10,4,6),1000)
id = rep(1:1000,each=10)
df = data.frame(id,xcat,yvalue1,yvalue2)
for(i in seq(1, length(unique(df$id)), by=100)){
print(
ggplot(subset(df, id %in% unique(df$id)[i:(i+99)]), aes(x=xcat)) +
annotate("line", y=yvalue1, x=xcat, colour="cornflowerblue") +
annotate("line", y=yvalue2, x=xcat, colour="grey20") +
theme(axis.text.x = element_text(size=5),
axis.text.y = element_text(size=5),
strip.text = element_text(size=5)) +
facet_wrap(~id, ncol=10, nrow=10) +
expand_limits(y=0))
}
Any ideas on how I could reduce the height of that strip.background so that it doesn't take up so much space? Ideally it would be sized to the exact height of the id text.
As a bonus, how to reduce the spacing between facets? (Is there a setting in facet_wrap that I'm missing?)
It also takes a REALLY long time to render in RStudio with facet_wrap (without facet_wrap it is much faster.
