How to tweak the extent to which an axis is drawn in ggplot2?

前端 未结 2 1926
温柔的废话
温柔的废话 2021-01-03 02:16

I am relatively new to ggplot2, having used base graphics in R for many years. One thing I always liked about base graphics is the extra padding in the axes, so that the tw

2条回答
  •  萌比男神i
    2021-01-03 02:34

    You can tweak this behavior by influencing the way the y-axis is scaled. ggplot2 usually chooses the limits according to the data and expands the axis a litte.

    The following example sets expansion to zero and uses custom limits instead for more control over the axes. As you can see, however, having the axes end at the maximum value is not always beneficial as the point characters may get cut off. So a little extra space is advised..

    require(ggplot2)
    x <- y <- 1:10
    qplot(x, y) + theme_classic() +
      scale_y_continuous(limits=c(-0.5,10), expand=c(0,0))
    

提交回复
热议问题