2013-05-17 90 views
2

我试图将这些堆叠在空间上成对分组,使得0W处理接近相应的6W处理,并在成对的不同处理之间具有更大的空间。我已经添加了一个专栏“组”来显示哪些对应该放在一起。如何在ggplot2中堆积条形组之间放置空间

数据:

 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:

structure(list(trt = structure(c(5L, 7L, 1L, 3L, 6L, 8L, 2L, 
4L, 5L, 7L, 1L, 3L, 6L, 8L, 2L, 4L), .Label = c("Native_D0 0W", 
"Native_D0 6W", "Native_D707 0W", "Native_D707 6W", "Notill_D0 0W", 
"Notill_D0 6W", "Notill_D707 0W", "Notill_D707 6W"), class = "factor"), 
    org = structure(c(2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 1L, 1L, 
    1L, 1L, 1L, 1L, 1L, 1L), .Label = c("bacteria", "fungi"), class = "factor"), 
    time = structure(c(1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 1L, 1L, 
    1L, 1L, 2L, 2L, 2L, 2L), .Label = c("0W", "6W"), class = "factor"), 
    copy = c(97800000, 15500000, 40200000, 10400000, 55100000, 
    14300000, 1.6e+07, 8640000, 2.98e+08, 77900000, 2.33e+08, 
    2.2e+08, 3.37e+08, 88400000, 3.24e+08, 1.89e+08), group = structure(c(1L, 
    2L, 3L, 4L, 1L, 4L, 3L, 2L, 1L, 2L, 3L, 4L, 1L, 4L, 3L, 2L 
    ), .Label = c("a", "b", "c", "d"), class = "factor")), .Names = c("trt", 
"org", "time", "copy", "group"), class = "data.frame", row.names = c(NA, 
-16L)) 

代码:

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")) 
+3

如果您将数据置于更易于使用的形式,您会发现更愿意帮助的人。尝试在你的数据框上使用'dput()',这将以一种易于使用的方式为我们提供数据。 – alexwhan

回答

3

我认为你可以做你想做的与facet,如果你做的情节p,只需添加:

p + facet_wrap(~group,nrow = 1) 

获得: enter image description here

如果你是不同的东西后,请重新定义。

+0

是的,那是有效的。我想我应该想到这一点。 – user2055130