ggplot2绘图结果往往X轴和Y轴的截距交点往往不是原点:譬如下图y轴就不是起始于0
调整坐标起始位点可以利用scale_y_continuous(expand = c(0, 0))或者scale_x_continuous(expand = c(0, 0))
expand的解释如下
expand | A numeric vector of length two giving multiplicative and additive expansion constants. These constants ensure that the data is placed some distance away from the axes. The defaults are c(0.05, 0) for continuous variables, and c(0, 0.6)for discrete variables.
连续性和离散型都涉及,默认值不同,离散型scale_y_discrete 或者scale_x_discrete,这里针对连续性进行介绍:
|
参考画图数据和代码 http://www.omicsclass.com/article/92
修改y轴连续性坐标起点:y = p + scale_y_continuous(expand=c(0,0))
如果针对x离散型的调整呢?尝试调整数,使柱子紧贴Y轴:x = p + scale_x_discrete(expand=c(0,0))