Avoid clipping of points along axis in ggplot

user1267299 picture user1267299 · Mar 13, 2012 · Viewed 7.2k times · Source

I am plotting a time series with mean values of a response variable as points (y-axis) by month (x-axis).

Values lying on the x-axis (i.e. 0 values) are clipped. I can change the limits of the y-axis to include some padding below 0, but I prefer not to.

Is there a way to plot these 0 points in front of, or on-top of the x-axis?

Answer

baptiste picture baptiste · Mar 13, 2012

Try this,

q <- qplot(1:10,1:10,size=I(10)) + scale_y_continuous(expand=c(0,0))
gt <- ggplot_gtable(ggplot_build(q))
gt$layout$clip[gt$layout$name=="panel"] <- "off"
grid.draw(gt)

clipoff