您真正需要的是:
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"
相同的結果,即只有繪製了迴歸線。
panel
參數xyplot
和一般的格點繪圖函數是非常強大的,但並非總是需要這麼複雜的東西。基本上你需要通過一個函數panel
,這個函數可以繪製每個面板上的東西。要修改您的代碼以執行您想要的操作,我們還需要添加對panel.xyplot()
的調用。例如: -
xyplot(yyy ~ xxx | zzz,
panel = function(x, y, ...) {
panel.xyplot(x, y, ...)
panel.lmline(x, y, ...)
})
它也是通過...
通過在各個面板的功能,所有其他參數是非常有用的,在這種情況下,你需要...
在你的匿名函數的參數(如上圖所示)。事實上,你也許可以寫面板功能部分爲:
xyplot(yyy ~ xxx | zzz,
panel = function(...) {
panel.xyplot(...)
panel.lmline(...)
})
但我通常添加x
和y
參數僅僅是明確的。
Gavin謝謝你的回答。 – Selvam