An embedded and charset-unspecified text was scrubbed... Name: not available URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20111017/15696755/attachment.pl>
multiple lines with the same data frame?
2 messages · Adel ESSAFI, R. Michael Weylandt
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:
Bonjour I have this data frame and I am newbie in R. I want to ask if it is possible to draw 10 lines in a plot such that: a line for every colomn, the x - axis is the second column and the y-axis is the third one. Thank you for any input 1 ? 0 ?1094442 1 ? 0.2 ?1163576.2 1 ? 0.4 ?1238539.6 1 ? 0.6 ?1303510.4 1 ? 0.8 ?1376573.2 1 ? 1 ?1454175 2 ? 0 ?1076068 2 ? 0.2 ?1139246 2 ? 0.4 ?1212344 2 ? 0.6 ?1277591.8 2 ? 0.8 ?1346156.6 2 ? 1 ?1410058 3 ? 0 ?1097901 3 ? 0.2 ?1173643.2 3 ? 0.4 ?1258849.8 3 ? 0.6 ?1343001.6 3 ? 0.8 ?1427705.8 3 ? 1 ?1507793 4 ? 0 ?1197047 4 ? 0.2 ?1292918.6 4 ? 0.4 ?1383640.8 4 ? 0.6 ?1480487.8 4 ? 0.8 ?1571557.6 4 ? 1 ?1659578 5 ? 0 ?1120010 5 ? 0.2 ?1200076.6 5 ? 0.4 ?1279653 5 ? 0.6 ?1360494.6 5 ? 0.8 ?1437223.2 5 ? 1 ?1512636 6 ? 0 ?1082650 6 ? 0.2 ?1154676.6 6 ? 0.4 ?1223416.6 6 ? 0.6 ?1297593.6 6 ? 0.8 ?1366764.6 6 ? 1 ?1432705 7 ? 0 ?1023590 7 ? 0.2 ?1077783.8 7 ? 0.4 ?1133154.2 7 ? 0.6 ?1190296 7 ? 0.8 ?1244411.4 7 ? 1 ?1297709 8 ? 0 ?1042257 8 ? 0.2 ?1107452.8 8 ? 0.4 ?1174574.8 8 ? 0.6 ?1238547.6 8 ? 0.8 ?1301507.6 8 ? 1 ?1363338 9 ? 0 ?1066917 9 ? 0.2 ?1136411.8 9 ? 0.4 ?1202822 9 ? 0.6 ?1273514.8 9 ? 0.8 ?1340641.8 9 ? 1 ?1408249 10 ? 0 ?1069685 10 ? 0.2 ?1138909 10 ? 0.4 ?1213284.2 10 ? 0.6 ?1282508.8 10 ? 0.8 ?1346093.2 10 ? 1 ?1410707 ? ? ? ?[[alternative HTML version deleted]]
______________________________________________ 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.