Skip to content
Prev 274659 / 398506 Next

multiple lines with the same data frame?

There are indeed many, many ways in R to do something like you've
described. If you are just a beginner, I'd recommend something simple:

suppose your data is called df and the columns named are "id", "x'',
and "y" respectively.

with(df, plot(x[id == 1], y[id==1], ylim = range(y), type="l")
# Call plot to set up the plot using the data for the first category.
The only tweak we make is to extend the y axis to cover all the y's we
might see; we also use a type="l" to get a line instead of points.

for (i in 2:10) {
    with(df, lines(x[id == i], y[id == i], col = i))
}
# Loop over the other categories and add them to our plot with the
lines() command; note that you wouldn't use plot directly because it
starts a new plot (most of the time)

This sort of stuff should be covered in any beginners manual, but
hopefully this gets you off to a good start.

Michael Weylandt
On Mon, Oct 17, 2011 at 11:58 AM, Adel ESSAFI <adelessafi at gmail.com> wrote: