用点阵图形上的回归线绘制xyplot [英] Plotting xyplot with regression line on lattice graphics

查看:119
本文介绍了用点阵图形上的回归线绘制xyplot的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经装好了晶格包装. 然后我运行:

I have loaded the lattice package. Then I run:

> xyplot(yyy ~ xxx | zzz, panel = function(x,y) { panel.lmline(x,y)}

这将产生绘图面板,其中显示了回归线,而没有xyplots. 我在做panel.lmline时没有完全了解它是如何完成的.我知道有一个数据参数,什么是数据,知道我有3个变量xxxyyyzzz?

This produces panels of plot, showing the regression line, without the xyplots. I am doing the panel.lmline without fully understanding how it is done. I know there is a data argument, what is the data, knowing that I have the 3 variables xxx, yyy, zzz?

推荐答案

您真正需要的是:

xyplot(yyy ~ xxx | zzz, type = c("p","r"))

其中type参数记录在?panel.xyplot

我不会全部引用

type: character vector consisting of one or more of the following:
      ‘"p"’, ‘"l"’, ‘"h"’, ‘"b"’, ‘"o"’, ‘"s"’, ‘"S"’, ‘"r"’,
      ‘"a"’, ‘"g"’, ‘"smooth"’, and ‘"spline"’.  If ‘type’ has more
      than one element, an attempt is made to combine the effect of
      each of the components.

      The behaviour if any of the first six are included in ‘type’
      is similar to the effect of ‘type’ in ‘plot’ (type ‘"b"’ is
      actually the same as ‘"o"’).  ‘"r"’ adds a linear regression
      line (same as ‘panel.lmline’, except for default graphical
      parameters). ‘"smooth"’ adds a loess fit (same as
      ‘panel.loess’).  ‘"spline"’ adds a cubic smoothing spline fit
      (same as ‘panel.spline’).  ‘"g"’ adds a reference grid using
      ‘panel.grid’ in the background (but using the ‘grid’ argument
      is now the preferred way to do so).  ‘"a"’ has the effect of
      calling ‘panel.average’, which can be useful for creating
      interaction plots.  The effect of several of these
      specifications depend on the value of ‘horizontal’.

如上所示,您可以通过传递type一个字符向量来依次添加这些字符.本质上,您的代码给出的结果与type = "r"相同,即,仅 绘制了回归线.

You can, as I showed above, add these in series by passing type a character vector. Essentially, your code gave the same result as type = "r", i.e. only the regression line was drawn.

xyplotpanel参数以及通常的莱迪思绘图功能非常强大,但并非总是需要如此复杂的东西.基本上,您需要传递panel一个函数,该函数将在绘图的每个面板上绘制内容.要修改您的代码以执行您想要的操作,我们还需要添加对panel.xyplot()的调用.例如:

The panel argument of xyplot, and Lattice plotting functions in general, is extremely powerful but not always required to so quite complex things. Basically you need to pass panel a function which will draw things on each panel of the plot. To modify your code to do what you wanted, we need to add a call to panel.xyplot() as well. E.g.:

xyplot(yyy ~ xxx | zzz,
       panel = function(x, y, ...) {
                 panel.xyplot(x, y, ...)
                 panel.lmline(x, y, ...)
               })

通过...传递各个面板函数上的所有其他参数也非常有用,在这种情况下,您需要...作为匿名函数中的参数(如上所示).实际上,您可以将面板功能部分写为:

It is also very useful to pass all other arguments on the individual panel functions via ..., in which case you need ... as an argument in your anonymous functions (as shown above). In fact, you can probably write that panel function part as:

xyplot(yyy ~ xxx | zzz,
       panel = function(...) {
                 panel.xyplot(...)
                 panel.lmline(...)
               })

但是我通常会添加xy参数只是为了清楚起见.

but I usually add the x and y arguments just to be clear.

这篇关于用点阵图形上的回归线绘制xyplot的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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