[R] color in grouped lattice xyplot plot

Katharina May may.katharina at googlemail.com
Thu Jun 11 22:19:54 CEST 2009


Hi,

I've got a data.frame object which I would like to plot in a lattice
xyplot grouped by a variable and using a value for the color of each
point which is stored in a variable in the same data.frame.

I tried the following code:

my.panel.xy <- function(x, y, ...){
      panel.xyplot(x, y,  ...)
      panel.lmline(x, y, lwd = 2)
      panel.abline(0, 1, col="red", lty=2)
      panel.grid(h = -1, v = -1, lty=1)
      }

xyplot(log(AGB) ~ log(BM_roots) | as.character(taxa),
data=sub_agb_data,main=list("AGB in dependence of BM_root [per
taxa!]",cex=0.7),
					ylab=list("log(AGB)",cex=0.7),xlab=list("log(BM_root)",cex=0.7),col=sub_agb_data$color,
panel = my.panel.xy)

xyplot(log(AGB) ~ log(BM_roots) | as.character(species),
data=sub_agb_data,main=list("AGB in dependence of BM_root [per
species!]",cex=0.7),
					ylab=list("log(AGB)",cex=0.7),xlab=list("log(BM_root)",cex=0.7),col=sub_agb_data$color,
panel = my.panel.xy)



Somehow the colors are not displayed correctly (it works if I use plot
in a for loop for each value for the variables for which I group my
lattice plots. The color variable is of type character so this
shouldn't be the reason)

The object sub_agb_object can be downloaded here:
http://www.wzw.tum.de/oekophys/fileadmin/sub_agb_data.rData

Maybe somebody has any idea how to make this work or what the problem might be?

Thanks,

        Katharina




More information about the R-help mailing list