r - ggplot : Showing x-axis line for each facet plot

标签 r ggplot2 axis facet-wrap geom-bar

我使用 ggplot 创建了一个分面图,它有 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 Axis 上有一条黑色实线。上面的 3 个图没有这条线,每个数据点只有一条虚线。

有谁知道如何在所有这些图的 x Axis 上放置一条实线?

谢谢
乔恩

编辑 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

最佳答案

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

关于r - ggplot : Showing x-axis line for each facet plot,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20993803/

相关文章:

r - 如何从 tibble 中删除非缺失值与其他行中的值子集匹配的行?

r - ggparcoord : color using discrete scale

r - 如何使用对数 y Axis 刻度制作 R 条形图?

opencv - 为 mips 处理器交叉编译 opencv

r - 如何将正态累积分布函数拟合到数据

linux - 如何在命令行中编写R?如何从命令行加载工作区?

r - 堆叠两列

r - 如何使用网格编辑 ggplot2 对象以将数学表达式添加到构面标签?

r - 只是 ggplot2 中的地毯(情节)?备择方案?

javascript - Chart.js - X Axis 刻度