具有分组回归线的叠加xyplot面板 [英] Superposed xyplot Panels with Grouped Regression Lines

查看:87
本文介绍了具有分组回归线的叠加xyplot面板的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I want to superpose multiple groups on a single panel in lattice, and want independent regression lines.

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

It is fairly easy to get multiple panels, each with a regression line by using a conditioning factor:

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
)

在叠加的xyplot中为所有点打印一个回归也很容易:

It is also fairly easy to print a single regression for all of the points in a superposed 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')
)

但这不是我所需要的.我将输入答案,但这似乎很混乱.也许那只是野兽的本质.

But this is not what I need. I will enter an answer to this, but it seems messy. Perhaps that's just the nature of the beast.

我正在寻找更容易理解的东西.晶格是首选,但也可以接受良好的ggplot解决方案.如果不清楚,我正在绘制要供Excel用户使用的图.

I'm looking for something that is easier to understand. Lattice is preferred, but a good ggplot solution may be accepted as well. If it isn't clear, I'm making plots for consumption by Excel users.

推荐答案

您可以使用 type 参数让Lattice为您完成面板工作

You can let Lattice do the panel-stuff for you using the type argument

xyplot(Petal.Width  ~ Petal.Length, groups = Species, data = iris, 
     type = c('p','r','g'),  
     auto.key = list(title='Species', space='right'))

这篇关于具有分组回归线的叠加xyplot面板的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆