r - 如何在 r car scatterplotMatrix 函数中设置回归线颜色

标签 r plot colors

如何更改 r car scatterplotMatrix 函数中回归线的颜色?

如果我运行这段代码:

# Load the iris dataset.
library(car)
data(iris)
 
# Plot #1: Basic scatterplot matrix of the four measurements
scatterplotMatrix(~Sepal.Length+Sepal.Width+Petal.Length+Petal.Width, data=iris)

然后我得到这个情节: enter image description here

检查显示点、平滑窗口和回归线都是相同的颜色,并且区分不是很清楚。

如果我想要蓝色的点、绿色的回归、橙色的平滑,我该怎么做?

最佳答案

这只需要仔细阅读文档?scatterplotMatrix

关于颜色的部分说:

col
colors for points; the default is carPalette starting at the second color. The color of the regLine and smooth are the same as for points but can be changed using the the regLine and smooth arguments.

regLine 的描述如下:

regLine=TRUE equivalent to regLine = list(method=lm, lty=1, lwd=2, col=col[1])

smooth 更复杂。描述位于详细信息部分。该描述很长,但包括:

You can also specify the colors you want to use for the mean and variance smooths with the arguments col.smooth and col.spread.

把这些放在一起,你可以得到

scatterplotMatrix(~Sepal.Length+Sepal.Width+Petal.Length+Petal.Width, 
    data=iris, regLine = list(col="green"),
    smooth=list(col.smooth="orange", col.spread="orange"))

Scatterplot with lines of different colors

关于r - 如何在 r car scatterplotMatrix 函数中设置回归线颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58731746/

相关文章:

r - c 使用rep或replicate或类似的语料库

RODBC 函数和错误/警告

r - 绘制 lm 返回的模型的结果

python - matplotlib 维恩图,6 个圆圈

r - 如何减小 R Plot 中图例的大小,同时仍使其可读?

r - 找到可能完全为正的 R 向量中第一个负数的位置

r - 根据多列排列长格式数据框并考虑改变排序方向

javascript - 谷歌可视化气泡图根据值更改图例颜色

c++ - QImage:使用颜色表从灰度转换为 RGB

colors - 如何从 fmt 中隐藏 ANSI 颜色转义代码