全部版块 我的主页
论坛 数据科学与人工智能 数据分析与数据科学 R语言论坛
6645 2
2016-07-17
关于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")
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

全部回复
2019-1-21 22:50:21
scatterplot函数里 spread和smoother.args两个参数显示不是图形参数 目前用的3.5.2版本r 求教
附件列表
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

2019-2-6 21:56:37
lion果 发表于 2019-1-21 22:50
scatterplot函数里 spread和smoother.args两个参数显示不是图形参数 目前用的3.5.2版本r 求教
最新的帮助:
?scatterplotMatrix

## Default S3 method:
scatterplotMatrix(x, smooth = TRUE,
    id = FALSE, legend = TRUE, regLine = TRUE,
    ellipse = FALSE, var.labels = colnames(x), diagonal = TRUE,
    plot.points = TRUE, groups = NULL, by.groups = TRUE,
    use = c("complete.obs", "pairwise.complete.obs"), col =
    carPalette()[-1], pch = 1:n.groups, cex = par("cex"),
    cex.axis = par("cex.axis"), cex.labels = NULL,
    cex.main = par("cex.main"), row1attop = TRUE, ...)


在R 语言实战中的8.2 OLS回归中
图8-3的语法是不对了。没有spread=FALSE,smoother.args=list(lty=2)的定义。
可以通过下面的语句实现:

scatterplot(weight
  ~ height, data = women, smooth=list(spread=FALSE,
  lty.smooth=2))

即为上面两个参数包含在smooth参数中。




二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

相关推荐
栏目导航
热门文章
推荐文章

说点什么

分享

扫码加好友,拉您进群
各岗位、行业、专业交流群