Reputation: 1
geom_line has big gap in line two sides, how to remove this gap!
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()
Upvotes: 0
Views: 568
Reputation: 24252
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
Upvotes: 3