在ggplot2中的特定构面之间添加空间(facet_grid)

艾米莉

我已经能够在所有构面之间添加垂直间隔(仅在构面之间更改水平间隔(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之间)

w
library(grid)
gt = ggplot_gtable(ggplot_build(example))
gt$widths[7] = 4*gt$widths[7]
grid.draw(gt)

在此处输入图片说明

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

在ggplot2中旋转切换的构面标签facet_grid

如何使用ggplot2 facet_grid注释没有数据的构面?

ggplot2:从图中删除未使用的因子级别组合的构面(facet_grid)

是否可以在ggplot2中的facet_wrap中轻松添加“(全部)”构面?

ggplot2:添加用于facet_grid的变量的名称

ggplot2 facet_grid:如何修复geom_col中列之间的不同间距

ggplot2:在 facet_grid 中按组添加水平线

在facet_grid中订购嵌套的构面标签

ggplot2中的facet_grid错误

如何使用facet_grid(ggplot2)在每个构面上绘制多条线

ggplot2和facet_wrap-消除构面之间的垂直距离

每条刻面线具有不同 y 轴的 ggplot2 刻面:如何从 facet_grid 和 facet_wrap 中获得“最佳”?

更改facet_grid中的构面标签并同时添加geom_vline时发生错误

在ggplot2中使用facet_grid()函数时,如何使用labeller()函数获取列总计显示在构面的标签中

重新排列facet_grid并将其添加到ggplot2的geom_bar中

如何从ggplot2 facet_wrap删除构面?

ggplot2中的facet_wrap()和facet_grid()有什么区别?

ggplot2中的构面旋转

在ggplot2构面之间添加空格和三个点(省略号)以指示省略的构面

在某些图中添加y = 0线facet_grid ggplot2

ggplot2和facet_grid:为每个图添加最大值

结合 facet_grid (ggplot2) 和 denscomp (fitdistrplus)

python plotnine:facet_grid中的标签编辑器不更改构面标题

如何在ggplot2中使用facet_grid制作甜甜圈图?

如何在ggplot2中按组为facet_grid着色?

使用ggplot2中的facet_grid更改中断次数

ggplot2 R中的facet_grid函数的非线性拟合

`ggplot2` 中的 `annotate` 与 `facet_grid` 结合时会报告错误

变更单保证金显示在facet_grid ggplot2中?