关于scatterplot()或scatterplotMatrix()函数,按照一些R语言的书籍所述,会出现如下类似的命令:
> scatterplotMatrix(~mpg+disp+drat+wt,data=mtcars,spread=F,lty.smooth=2,main="Scatter Plot Matrix via car Package")
而运行结果往往会出现如下警告:
There were 50 or more warnings (use warnings() to see the first 50)
警告信息:
1: In plot.window(...) : "lty.smooth"不是图形参数
2: In plot.xy(xy, type, ...) : "lty.smooth"不是图形参数
3: In title(...) : "lty.smooth"不是图形参数
4: In plot.window(...) : "lty.smooth"不是图形参数
5: In plot.xy(xy, type, ...) : "lty.smooth"不是图形参数
6: In title(...) : "lty.smooth"不是图形参数
7: In axis(side = side, at = at, labels = labels, ...) : "lty.smooth"不是图形参数
8: In plot.window(...) : "lty.smooth"不是图形参数
显然,lty.smooth=2这一参数设置并不会出现我们预期的效果。
现在,我们来看看scatterplotMatrix()函数的信息(参见“?scatterplotMatrix”)
scatterplotMatrix(x, var.labels=colnames(x),
diagonal=c("density", "boxplot", "histogram", "oned", "qqplot", "none"),
adjust=1, nclass,
plot.points=TRUE, smoother=loessLine, smoother.args=list(), smooth, span,
spread = !by.groups, reg.line=lm,
transform=FALSE, family=c("bcPower", "yjPower"),
ellipse=FALSE, levels=c(.5, .95), robust=TRUE,
groups=NULL, by.groups=FALSE,
use=c("complete.obs", "pairwise.complete.obs"),
labels, id.method="mahal", id.n=0, id.cex=1, id.col=palette()[1],
col=if (n.groups == 1) palette()[3:1] else rep(palette(), length=n.groups),
pch=1:n.groups, lwd=1, lty=1,
cex=par("cex"), cex.axis=par("cex.axis"), cex.labels=NULL,
cex.main=par("cex.main"),
legend.plot=length(levels(groups)) > 1, legend.pos=NULL, row1attop=TRUE, ...)
我们主要关注红色字体部分——smoother=loessLine, smoother.args=list()
其中,参数smoother指定了光滑曲线的绘制方法,默认采用loessLine()函数(关于该函数的具体信息参见“?loessLine”)来进行绘制。
而参数smoother.args=list()则指定了光滑曲线的线条长度,宽度等细节信息
loessLine()函数绘制的曲线的默认细节参数如下:
smoother.args=list(lty=1,
lwd=2, lty.spread=2, lwd.spread=1, span=0.5, degree=2,
family="symmetric", iterations=4)
所以,我们可以用参数smoother.args=list(lty=2)来实现lty.smooth=2所期望的效果。
即上述开始提出的命令可改写为:
> scatterplotMatrix(~mpg+disp+drat+wt,data=mtcars,spread=F,smoother.args=list(lty=2),main="Scatter Plot Matrix via car Package")