R 中线型的更多变化(添加点、加号……)

More variation in line types in R (add dots, plusses...)

我在 R 的一张图中绘制了多条回归线。我使用 abline() 中的 lty= 设置来区分它们。但是,一旦我有超过三行,我就发现这很不令人满意:所有 line types 看起来都太相似了。 (我的图表需要 black/white。)

我确信在 R 中一定有一种组合符号和线条的方法(有一条没有符号的虚线,一条有十字等),但无法弄清楚,至少对于 abline()。我基本上是在考虑组合 pch with line types or more interesting lines like here.

中的符号

这个 question 用于定义线型的细节,但在这里并没有真正帮助我...

谢谢!

您可以通过利用 predictabline 分成几段来实现,然后您可以指定一个 pch= 反对。通过手动指定点,您可以决定在 length.out= 参数中自定义刻度线的频率:

x <- 1:10
y <- jitter(x,5)
fit <- lm(y~x)
plot(x,y)

pts <- seq(min(x),max(x),length.out=10)
lines(pts, predict(fit, list(x=pts)), type="o", pch="^")