[R] lattice xyplot: plot multiple lines with different colors
Bram Kuijper
a.l.w.kuijper at rug.nl
Thu Dec 28 15:08:48 CET 2006
Hi everyone,
I am using the lattice package to plot some simulation results, by using
the function xyplot(). However, I cannot find a way to plot multiple
lines within the same xyplot and to have each of the lines be drawn in a
different color.
This is what I am currently doing:
xyplot(a + b + c ~ x, my_data, panel = panel.lines)
but, of course, all lines are drawn in the same color.
What I would prefer, would be to first print a single line in an xyplot
and then add a new line, and so on (since I want to dynamically
determine the number of lines that need to be plotted). For example,
something like this would be nice:
for(i = 1:length(lines_to_be_drawn)) {
xyplot(lines_to_be_drawn[i] ~ x, my_data, panel = {some function
setting a different color});
// do some other functions like plotting legend, parameters
}
(although in this putative example, a new xyplot is drawn over the old
one every time).
anyone any idea to plot multiple lines with different colors in a single
xyplot? I'd like to stick to the lattice package, since this package has
more layout possibilities over the traditional plotting functions in R.
cheers,
Bram
More information about the R-help
mailing list