R 如何在ggplot2中的堆叠钢筋组之间放置空间

R 如何在ggplot2中的堆叠钢筋组之间放置空间,r,ggplot2,R,Ggplot2,我试图将堆栈按空间成对分组,以便0W处理接近相应的6W处理,不同处理对之间的空间更大。我已经包括了一个“组”专栏,以显示哪些对应该在一起 数据: trt org time copy group 1 Notill_D0 0W fungi 0W 9.78e+07 a 2 Notill_D707 0W fungi 0W 1.55e+07 b 3 Native_D0 0W fungi 0W 4.

我试图将堆栈按空间成对分组,以便0W处理接近相应的6W处理,不同处理对之间的空间更大。我已经包括了一个“组”专栏,以显示哪些对应该在一起

数据:

       trt            org   time  copy     group
1    Notill_D0 0W    fungi   0W 9.78e+07     a
2  Notill_D707 0W    fungi   0W 1.55e+07     b
3    Native_D0 0W    fungi   0W 4.02e+07     c
4  Native_D707 0W    fungi   0W 1.04e+07     d
5    Notill_D0 6W    fungi   6W 5.51e+07     a
6  Notill_D707 6W    fungi   6W 1.43e+07     d
7    Native_D0 6W    fungi   6W 1.60e+07     c
8  Native_D707 6W    fungi   6W 8.64e+06     b
9    Notill_D0 0W bacteria   0W 2.98e+08     a
10 Notill_D707 0W bacteria   0W 7.79e+07     b
11   Native_D0 0W bacteria   0W 2.33e+08     c
12 Native_D707 0W bacteria   0W 2.20e+08     d
13   Notill_D0 6W bacteria   6W 3.37e+08     a
14 Notill_D707 6W bacteria   6W 8.84e+07     d
15   Native_D0 6W bacteria   6W 3.24e+08     c
16 Native_D707 6W bacteria   6W 1.89e+08     b
dput:

代码:


colvec我想你可以用
facet
做你想做的事,如果你绘制的图是
p
,只需添加:

p + facet_wrap(~group,nrow = 1) 
要获得:


如果您的目标不同,请重新定义。

如果您将数据以更易于使用的形式提供,您会发现人们更愿意提供帮助。尝试在您的数据帧上使用
dput()
,这将以易于使用的方式为我们提供数据。
    colvec <-c("blue", "orange")

ggplot(Suz2, aes(factor(trt), copy)) + 
  geom_bar(aes(fill = factor(org)), stat="identity", width = 0.7) +
  scale_fill_manual(values = colvec)+
  theme(panel.background = element_rect(fill='white', colour='white'), 
        panel.grid = element_line(color = NA),
        panel.grid.minor = element_line(color = NA),
        panel.border = element_rect(fill = NA, color = "black"),
        axis.text.x  = element_text(size=10, colour="black", face = "bold"),  
        axis.title.x = element_text(vjust=0.1, face = "bold"),
        axis.text.y = element_text(size=12, colour="black"),
        axis.title.y = element_text(vjust=0.2, size = 12, face = "bold"))
p + facet_wrap(~group,nrow = 1)