[R] xyplot with lowess curves

Sundar Dorai-Raj sdorairaj at gmail.com
Mon Feb 2 20:42:46 CET 2009


You'll need a custom panel function. It would also help if you
provided a reproducible example:

xyplot (
  SnowLineElevation ~ Year | Model,
  data = data,
  panel = function(x, y, col, ...) {
    col <- ifelse(panel.number() == 1, "red", "green")
    panel.xyplot(x, y, col = "blue", ...)
    panel.loess(x, y, col = col)
  },
  ylim = c(0,1800),
  pch = 21,
  xlab = 'Year',
  ylab = 'Snowline Elevation [m]'
)

Alternatively, you can use the group argument in conjunction with the panels:

xyplot(SnowLineElevation ~ Year | Model, data, groups = Model, type =
c("p", "smooth"))

if you want the points and the lines to be the same color.

--sundar

On Mon, Feb 2, 2009 at 10:20 AM, Hutchinson,David [PYR]
<David.Hutchinson at ec.gc.ca> wrote:
> I am trying to change the attributes of the lowess lines fit to an
> xyplot command, but have been unsuccessful in my search of the online
> help. Right now, both the points and lowess line come out in the same
> color (blue). I am unsure how I can change the properties of the lowess
> line separately.
>
> xyplot (
>  SnowLineElevation ~ Year | Model,
>  data = data,
>  ylim = c(0,1800),
>  type = c('p','smooth'),
>  col = 'blue',
>  pch = 21,
>  xlab = 'Year',
>  ylab = 'Snowline Elevation [m]'
> )
>
> Any help would be much appreciated,
>
> Dave
>
>        [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>




More information about the R-help mailing list