Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ggplot: Showing x-axis line for each facet plot

I have created a facet plot using ggplot which has 4 rows and 1 column with this code:

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

The issue I have is that only the bottom plot has a solid black line on the x-axis. The 3 plots above do not have this line and only have a dashed line for each data point.

Does anyone know how I can put a solid line on the x-axis for all of these plots?

Thanks Jon

Edit 1: Data

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
like image 589
user2553008 Avatar asked Jan 08 '14 11:01

user2553008


2 Answers

You might have found a solution already, but I've always just included the line geom_hline(yintercept=0) to add the x-axis origin line to my plots. Its a serious hack, but it also provides you some aesthetic control, and I haven't found a better work around.

like image 75
escott55 Avatar answered Sep 20 '22 04:09

escott55


Hard to tell without being able to produce your plot but does using scales = "free_x" in your facet wrap call solve the problem?

For example:

facet_wrap(~ Site, ncol=1,nrow=4, scales = "free_x")
like image 20
Adam Kimberley Avatar answered Sep 19 '22 04:09

Adam Kimberley