> df<-data.frame(x=c(1,2,3),y=c(2,3,4),colour=c("a","b","c"))
> ggplot(df,aes(x,y,colour=factor(colour)))+geom_line(aes(group=1))
> xgrid<-with(df,seq(min(x),max(x),length=15))
> xgrid
[1] 1.000000 1.142857 1.285714 1.428571 1.571429 1.714286 1.857143 2.000000
[9] 2.142857 2.285714 2.428571 2.571429 2.714286 2.857143 3.000000
> approx(df$x,df$y,xout=xgrid)
$x
[1] 1.000000 1.142857 1.285714 1.428571 1.571429 1.714286 1.857143 2.000000
[9] 2.142857 2.285714 2.428571 2.571429 2.714286 2.857143 3.000000
$y
[1] 2.000000 2.142857 2.285714 2.428571 2.571429 2.714286 2.857143 3.000000
[9] 3.142857 3.285714 3.428571 3.571429 3.714286 3.857143 4.000000
xout:an optional set of numeric values specifying where interpolation is to take place.
数值型变量的插值位置
> approx(df$x,df$y,n=15)
$x
[1] 1.000000 1.142857 1.285714 1.428571 1.571429 1.714286 1.857143 2.000000
[9] 2.142857 2.285714 2.428571 2.571429 2.714286 2.857143 3.000000
$y
[1] 2.000000 2.142857 2.285714 2.428571 2.571429 2.714286 2.857143 3.000000
[9] 3.142857 3.285714 3.428571 3.571429 3.714286 3.857143 4.000000
发现不指定xout的时候,与上面指的产生的随机数一样,等差序列插值