ggplot:显示每个构面图的x轴线

时间:2014-01-08 11:06:14

标签: r ggplot2 axis facet-wrap geom-bar

我使用ggplot创建了一个facet plot,它有4行1列,代码如下:

ggplot(data=c, aes(x=Time, y=X.mean, fill = Site, width=.1)) +  
  geom_bar(stat="identity", position=position_dodge(),  width=0.5,colour="black",        show_guide=FALSE) +
  ylab(NULL) + xlab(NULL) +
   geom_errorbar(aes(ymax= X.Passes.sd, ymin= 0),
            size = 0.7, width = 0.3,position = position_dodge(0.9))+
  scale_fill_manual(values=c("cadetblue2", "royalblue1", "mediumseagreen", "green4")) +
  scale_y_continuous(breaks=number_ticks(12), expand = c(0, 0), limits=c(0,20)) +
  scale_x_discrete(expand = c(0, 0), limits=c("17:00","18:00","19:00","20:00","21:00","22:00","23:00","00:00","01:00","02:00","03:00","04:00", "05:00", "06:00")) +
  facet_wrap(~ Site, ncol=1,nrow=4)+
  theme_bw() + 
  theme(strip.text.x = element_text(size=18))+
  theme(axis.title.y=element_text(size = 18)) +
  theme(panel.grid.minor=element_blank(), panel.grid.major=element_blank())+
  theme(axis.text.x=element_text(angle = 45, hjust=1, vjust=1, size = 18))+
  theme(axis.text.y=element_text(size = 18))+
  theme(panel.border = element_blank())+
  theme(axis.line = element_line(color = 'black'))+
  theme(axis.title.y=element_text(vjust=0.3, size=20))+
  theme(strip.background = element_rect(colour="white", fill="white"))+
  theme(legend.position = "none")

我遇到的问题是只有底部的图在x轴上有一条纯黑线。上面的3个图没有这条线,每个数据点只有一条虚线。

有谁知道如何在x轴上为所有这些图设置实线?

由于 乔恩

编辑1:数据

Date    Site    Passes
02/11/2013  RM1 85
03/11/2013  RM1 254
04/11/2013  RM1 636
05/11/2013  RM1 610
06/11/2013  RM1 408
07/11/2013  RM1 293
08/11/2013  RM1 388
09/11/2013  RM1 513
10/11/2013  RM1 190
11/11/2013  RM1 333
12/11/2013  RM1 264
13/11/2013  RM1 261
14/11/2013  RM1 364
15/11/2013  RM1 1
16/11/2013  RM1 238
17/11/2013  RM1 149
18/11/2013  RM1 242
19/11/2013  RM1 225
20/11/2013  RM1 196
21/11/2013  RM1 68
22/11/2013  RM1 292
23/11/2013  RM1 159
24/11/2013  RM1 65
25/11/2013  RM1 166
26/11/2013  RM1 44
27/11/2013  RM1 0
28/11/2013  RM1 56
29/11/2013  RM1 378
30/11/2013  RM1 34
01/12/2013  RM1 43
02/12/2013  RM1 518
03/12/2013  RM1 286
04/12/2013  RM1 175
05/12/2013  RM1 169
06/12/2013  RM1 138
07/12/2013  RM1 445
08/12/2013  RM1 1153
09/12/2013  RM1 616
10/12/2013  RM1 1
02/11/2013  RM2 1
03/11/2013  RM2 30
04/11/2013  RM2 210
05/11/2013  RM2 47
06/11/2013  RM2 8
07/11/2013  RM2 66
08/11/2013  RM2 3
09/11/2013  RM2 7
10/11/2013  RM2 4
11/11/2013  RM2 13
12/11/2013  RM2 16
13/11/2013  RM2 31
14/11/2013  RM2 4
15/11/2013  RM2 0
16/11/2013  RM2 9
17/11/2013  RM2 24
18/11/2013  RM2 5
19/11/2013  RM2 47
20/11/2013  RM2 12
21/11/2013  RM2 3
22/11/2013  RM2 43
23/11/2013  RM2 8
24/11/2013  RM2 15
25/11/2013  RM2 26
26/11/2013  RM2 2
27/11/2013  RM2 0
28/11/2013  RM2 0
29/11/2013  RM2 9
30/11/2013  RM2 2
01/12/2013  RM2 1
02/12/2013  RM2 45
03/12/2013  RM2 26
04/12/2013  RM2 6
05/12/2013  RM2 8
06/12/2013  RM2 0
07/12/2013  RM2 0
08/12/2013  RM2 0
09/12/2013  RM2 0
10/12/2013  RM2 0
03/11/2013  RM3 14
04/11/2013  RM3 100
05/11/2013  RM3 22
06/11/2013  RM3 6
07/11/2013  RM3 35
08/11/2013  RM3 12
09/11/2013  RM3 30
10/11/2013  RM3 33
11/11/2013  RM3 3
12/11/2013  RM3 40
13/11/2013  RM3 88
14/11/2013  RM3 5
15/11/2013  RM3 10
16/11/2013  RM3 10
17/11/2013  RM3 13
18/11/2013  RM3 13
19/11/2013  RM3 20
20/11/2013  RM3 12
21/11/2013  RM3 3
22/11/2013  RM3 31
23/11/2013  RM3 1
24/11/2013  RM3 23
25/11/2013  RM3 11
26/11/2013  RM3 2
27/11/2013  RM3 0
28/11/2013  RM3 1
29/11/2013  RM3 23
30/11/2013  RM3 0
01/12/2013  RM3 0
02/12/2013  RM3 9
03/12/2013  RM3 19
04/12/2013  RM3 6
05/12/2013  RM3 8
06/12/2013  RM3 1
07/12/2013  RM3 1
08/12/2013  RM3 35
09/12/2013  RM3 7
10/12/2013  RM3 0
04/11/2013  RM4 371
05/11/2013  RM4 110
06/11/2013  RM4 36
07/11/2013  RM4 55
08/11/2013  RM4 45
09/11/2013  RM4 44
10/11/2013  RM4 10
11/11/2013  RM4 27
12/11/2013  RM4 86
13/11/2013  RM4 116
14/11/2013  RM4 55
15/11/2013  RM4 0
16/11/2013  RM4 95
17/11/2013  RM4 28
18/11/2013  RM4 50
19/11/2013  RM4 69
20/11/2013  RM4 51

2 个答案:

答案 0 :(得分:5)

您可能已经找到了解决方案,但我总是只包含行geom_hline(yintercept=0)以将x轴原点线添加到我的图中。它是一个严重的黑客,但它也为你提供了一些美学控制,我还没有找到更好的工作。

答案 1 :(得分:2)

很难说没有能够制作你的情节,但是在你的facet包裹调用中使用scales = "free_x"来解决问题?

例如:

facet_wrap(~ Site, ncol=1,nrow=4, scales = "free_x")