??我們似乎沒有擔(dān)心過數(shù)據(jù)點被畫到axes之外史辙,這是因為ggplot2會在data range和axes之間加一些padding妇穴,以保證數(shù)據(jù)和坐標軸不會重疊:
來自scale_x_continous()的usage
expand
For position scales, a vector of range expansion constants used to add some padding around the data to ensure that they are placed some distance away from the axes. Use the convenience function expansion() to generate the values for the expand argument. The defaults are to expand the scale by 5% on each side for continuous variables, and by 0.6 units on each side for discrete variables.
??expansion()
用來生成scale expansion vectors作為expand
參數(shù)的值耀盗。expansion()
接受兩個參數(shù)mult
和add
分別對應(yīng)生成乘性因子和加性因子励堡。
??加性參數(shù)和乘性參數(shù)的區(qū)別是:加性參數(shù)基于data variable擴展翩隧,乘性參數(shù)基于axis range進行擴展妓布。
expansion(mult = 0, add = 0)
輸入?yún)?shù):向量窿侈,若長度為1,如mult=0.1則range的上下均擴展10%秋茫;
若長度為2史简,如mult=(0.1,0.2),則向下擴展10%肛著,向上擴展20%圆兵。
> expansion(mult = c(0.1,0.2), add = c(3,4))
[1] 0.1 3.0 0.2 4.0
# 第一個值:乘性下限;第二個值:加性下限枢贿;第三個值:乘性上限殉农;第四個值:加性上限
??對scale函數(shù)中的expand
參數(shù),需要是一個長度為2或4的向量局荚。當(dāng)長度為2超凳,例如expand=c(0.1,0.2)
,表示分別向上下擴展10%耀态,向上下加0.2轮傍,等價于expand=c(0.1,0.2,0.1,0.2)
,等價于expand=expansion(mult=c(0.1,0.1),add=c(0.2,0.2))
首装,即expansion(mult=0.1,add=0.2)
创夜。