Removing empty spaces between bars in faceted barplot

流过昼夜 提交于 2021-02-05 08:38:11

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!