[R] xyplot with all columns of a data.frame on a single plot

Felix Andrews felix at nfrac.org
Tue Jul 27 05:40:44 CEST 2010


One method:

dd <- do.call(make.groups, mydata[,-1])
dd$X <- mydata$X
xyplot(data ~ X | which, dd)

Another method:

form <- paste(paste(colnames(mydata)[-1], collapse = " + "), "~ X")
xyplot(as.formula(form), mydata)

Yet another method:

library(latticeExtra)
xyplot.list(mydata[,-1], FUN = function(z, ...) xyplot(z ~ mydata$X, ...))


On 27 July 2010 12:26, Rajarshi Guha <rajarshi.guha at gmail.com> wrote:
> Hi, I have a data.frame with columns named X, D1, D2, D3
>
> I know I can get a single plot with 3 curves by doing
>
> xyplot(D1 + D2 + D3 ~ X, data)
>
> but in some cases I might have columns D1 ...  D10.
>
> Is there a way to plot all 10 columns without having to specify each
> individual term?
>
> (By analogy with formulae in lm, I thought, xyplot(. ~ X, data) would
> work, but it didn't)
>
> Thanks,
>
> --
> Rajarshi Guha
> NIH Chemical Genomics Center
>
> ______________________________________________
> 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.
>



-- 
Felix Andrews / 安福立
http://www.neurofractal.org/felix/



More information about the R-help mailing list