0

geom_line has big gap in line two sides, how to remove this gap!

geom_line

R scripts is listed as follow,

p <- ggplot(singJanS)+ geom_line(aes(x=sn,y=diff))
p <- p  + geom_hline(yintercept=seq(-0.8,0.8,by=0.4), linetype=2, colour="grey") +
  geom_vline(xintercept=seq(15,744,by=24), linetype=6, colour="red") +
  geom_vline(xintercept=seq(23,744,by=24), linetype=6, colour="blue") +
  ylab(Delta~T~'  ('~degree~C~')')+xlab("")+
  scale_x_continuous(breaks = c(0,120,240,360,480,600,720))+
  scale_y_continuous(breaks = c(-0.8,-0.4,0,0.4,0.8)) +theme_bw()
Marco Sandri
  • 23,289
  • 7
  • 54
  • 58

2 Answers2

3

The solution suggested by @Z.Lin works correctly.
The two gaps are removed if you add expand = c(0, 0) to scale_x_continuous().

set.seed(1)
singJanS <- data.frame(sn=1:740, diff=rnorm(740)/3)

p <- ggplot(singJanS)+ geom_line(aes(x=sn,y=diff))
p <- p  + geom_hline(yintercept=seq(-0.8,0.8,by=0.4), linetype=2, colour="grey") +
  geom_vline(xintercept=seq(15,744,by=24), linetype=6, colour="red") +
  geom_vline(xintercept=seq(23,744,by=24), linetype=6, colour="blue") +
  ylab(Delta~T~'  ('~degree~C~')')+xlab("")+
  scale_x_continuous(breaks = c(0,120,240,360,480,600,720),expand = c(0, 0))+
  scale_y_continuous(breaks = c(-0.8,-0.4,0,0.4,0.8)) +theme_bw()
p

enter image description here

Marco Sandri
  • 23,289
  • 7
  • 54
  • 58
0

Try adding to your code

    + scale_x_continuous(limits = c(0, 750))
R18
  • 1,476
  • 1
  • 8
  • 17