gpt4 book ai didi

r - 具有分组回归线的叠加 xyplot 面板

转载 作者:行者123 更新时间:2023-12-03 15:12:40 28 4
gpt4 key购买 nike

我想在格子中的单个面板上叠加多个组,并且想要独立的回归线。

获得多个面板相当容易,每个面板都有一条使用条件因子的回归线:

xyplot(
Petal.Width ~ Petal.Length | Species,
data = iris,
panel = function(x, y, ...) {
panel.xyplot(x, y, ...)
panel.abline(lm(y~x), col='#0080ff')
},
grid = TRUE
)

enter image description here

为叠加的 xyplot 中的所有点打印单个回归也相当容易:
xyplot(
Petal.Width ~ Petal.Length,
data = iris,
groups = Species,
panel = function(x, y, ...) {
panel.xyplot(x, y, ...)
panel.abline(lm(y~x))
},
grid = TRUE,
auto.key = list(title='Species', space='right')
)

enter image description here

但这不是我需要的。我会回答这个问题,但它看起来很困惑。或许这就是野兽的本性。

我正在寻找更容易理解的东西。格子是首选,但也可以接受一个好的 ggplot 解决方案。如果不清楚,我正在为 Excel 用户制作绘图。

最佳答案

这是我想出的:

xyplot(
Petal.Width ~ Petal.Length,
groups = Species,
data = iris,
panel = function(x, y, ...) {
panel.superpose(x, y, ...,
panel.groups = function(x,y, col, col.symbol, ...) {
panel.xyplot(x, y, col=col.symbol, ...)
panel.abline(lm(y~x), col.line=col.symbol)
}
)
},
grid = TRUE,
auto.key = list(title='Species', space='right')
)

enter image description here

关于r - 具有分组回归线的叠加 xyplot 面板,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14185600/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com