我有一个这样的情节,由以下内容组成:
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")
Run Code Online (Sandbox Code Playgroud)
我希望所有的条形都彼此相邻,并且在 x 轴上的 3、4、9 处没有间隙。我想这是因为 Nest 是一个数字而不是一个字符串。
我有dat$nest = as.factor(dat$nest)
如果您使用小平面,则它们之间共享轴。然而,scales争论可以让他们自由。
facet_wrap(~Year, scales = "free_x")
Run Code Online (Sandbox Code Playgroud)
http://ggplot2.tidyverse.org/reference/facet_wrap.html