【发布时间】:2018-08-13 20:23:25
【问题描述】:
我已经能够在所有构面之间添加垂直空间 (Alter just horizontal spacing between facets (ggplot2)),但无法在指定构面之间仅添加一个空间?
这是一个基于我的真实数据的示例(在真实图中我有堆积条):
mydf<-data.frame(year = rep(c(2016,2016,2016,2016,2016,2016,2017,2017,2017,2017,2017,2017),times = 2),
Area = rep(c('here','there'),times = 12),
yearArea = rep(c('here.2016','here.2017', 'there.2016','there.2017'), times = 12),
treatment = rep(c('control','control','control','treat', 'treat','treat'), times = 4),
response = rep(c('a','b','c','d'), times = 6),
count = rep(c(23,15,30,20), times = 6))
mycolour<-c("#999999", "#0072B2", "#009E73","#000000")
返回情节:
#default facet spacing
example<-ggplot(data=mydf, aes(x=treatment, y=count, fill=response)) +
geom_bar(stat="identity", width = 0.5) +
scale_fill_manual(values = mycolour, name = "Response") +
labs (y = "Count") +
facet_grid(~yearArea) +
theme_bw()
example
#spacing between each facet
spacedex<-example + theme(panel.spacing.x=unit(2, "lines"))
spacedex
如何将添加的空间限制为仅在第二个和第三个方面之间? (here.2017 和 there.2016 之间)
【问题讨论】: