[R] Multiple Line Plots with xyplot
David Winsemius
dwinsemius at comcast.net
Thu Nov 18 03:36:42 CET 2010
On Nov 17, 2010, at 5:38 PM, Elliot Joel Bernstein wrote:
> I'm trying to make multiple line plots, each with a different color,
> using the xyplot command. Specifically, I have an NxK matrix Y and
> an Nx1 matrix x. I would like the plot to contain a line for each
> (x, Y[,i]), i=1:K. I know something like
>
> xyplot(Y[,1] + Y[,2] + Y[,3] ~ x, type='l')
>
> will work, but if Y is large, this notation can get very awkward. Is
> there a way to do something simpler, along the lines of
>
> xyplot(Y ~ x, type='l')
Perhaps:
x2 <- rep(x, K)
mydat <- data.frame(y =c(Y) , x = x2, id= rep(1:K, each=N)
# not exactly sure I have the N's and K's properly aligned
# but that COULD have been tested with some reproducible data
# which we are both too busy to provide.
xyplot(y ~ x, mydat, groups = id, type="l")
>
> Thanks.
>
> - Elliot
>
> --
> Elliot Joel Bernstein, Ph.D. | Research Associate | FDO Partners, LLC
> 134 Mount Auburn Street | Cambridge, MA | 02138
> Phone: (617) 503-4619 | Email: elliot.bernstein at fdopartners.com
>
> ______________________________________________
> 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.
David Winsemius, MD
West Hartford, CT
More information about the R-help
mailing list