Alles, was Sie wirklich brauchen, ist:
xyplot(yyy ~ xxx | zzz, type = c("p","r"))
wo das type
Argument in ?panel.xyplot
dokumentiert ich alles aber
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’.
Sie können nicht zitieren wird, wie ich zeigte, oben, fügen Sie diese in Reihe, indem Sie type
einen Zeichenvektor übergeben. Im Wesentlichen hat Ihr Code das gleiche Ergebnis wie type = "r"
, d. H. nur die Regressionslinie wurde gezogen.
Das panel
Argument von xyplot
, und Gitter-Plotten Funktionen im Allgemeinen, ist sehr mächtig, aber nicht immer erforderlich, um so ziemlich komplexe Dinge. Grundsätzlich müssen Sie panel
eine Funktion übergeben, die Dinge auf jedem Panel der Handlung zeichnen wird. Um Ihren Code so zu modifizieren, dass er das tut, was Sie wollten, müssen wir auch einen Anruf an panel.xyplot()
hinzufügen. Z.B .:
xyplot(yyy ~ xxx | zzz,
panel = function(x, y, ...) {
panel.xyplot(x, y, ...)
panel.lmline(x, y, ...)
})
Es ist auch sehr nützlich, alle anderen Argumente zu den einzelnen Panel-Funktionen über ...
Pass, in dem Fall, dass Sie ...
als Argument in der anonymen Funktionen benötigen (wie oben dargestellt). In der Tat, können Sie wahrscheinlich, dass die Panel-Funktion Teil als schreiben:
xyplot(yyy ~ xxx | zzz,
panel = function(...) {
panel.xyplot(...)
panel.lmline(...)
})
aber ich hinzufügen, in der Regel die x
und y
Argumente nur klar werden.
Gavin danke für Ihre Antwort. – Selvam