问题
I have a plot like this, made from:
plot = ggplot(dat, aes(x=Nest)) + geom_bar(aes(fill=MotherID), position = position_stack(reverse = TRUE)) + facet_wrap(~Year) + scale_fill_grey(start = 0, end = .9) + theme(axis.text.x = element_text(angle = 90, hjust = 1)) + theme(legend.position="none") + ylab("Number of offpsring")
I'd like all the bars to be next to each other without the gaps between them at like 3, 4, 9 on the x axis. I guess it is because nest is a number rather than a string.
I have dat$nest = as.factor(dat$nest)
回答1:
If you use facets, the axes are shared between them. However the scales argument can set them free.
facet_wrap(~Year, scales = "free_x")
http://ggplot2.tidyverse.org/reference/facet_wrap.html
来源:https://stackoverflow.com/questions/49287170/removing-empty-spaces-between-bars-in-faceted-barplot