# Line Graph - Greater than 2 variables on plot Classic List Threaded 8 messages Open this post in threaded view
|

## Line Graph - Greater than 2 variables on plot

 Hello all, I was wondering if anyone knew how to construct a multiple line graph on R, where there are 2 (or more) sets of data points plotted against some x axis of data, and you can draw a line on the graph connecting each set of data points. For example: A               B              C          D 0.6566        2.1185        1.2320        5 0.647         2.0865        1.2325        10 0.6532        2.1060        1.2287        15 0.6487        2.1290        1.2313        20 0.6594        2.1285        1.2341        25 0.6577        2.1070        1.2343        30 0.6579        2.1345        1.2340        35 0.6734        2.1705        1.2362        40 0.675         2.1845        1.2372        45 0.6592        2.1550        1.2340        50 0.6647        2.1710        1.2305        55 Would there be a way: a) To graph all the points of data in sets A, B and C as Y coordinates on one graph, using the points in set D as the X-axis/coordinates for all 3 sets (A, B and C)? b) To be able to draw 3 lines on the graph that connect each set of data (1 line connects all the A points, one line connects all the B points, one line connects all the C points) I couldn't find anything in the examples or the help section about multiple lines on the same graph, only one line. Thanks, Wayne ______________________________________________ [hidden email] mailing list https://stat.ethz.ch/mailman/listinfo/r-helpPLEASE do read the posting guide http://www.R-project.org/posting-guide.htmland provide commented, minimal, self-contained, reproducible code.
Open this post in threaded view
|

## Re: Line Graph - Greater than 2 variables on plot

 On 21/09/2007, at 1:57 PM, Wayne Aldo Gavioli wrote: > > > Hello all, > > I was wondering if anyone knew how to construct a multiple line   > graph on R, > where there are 2 (or more) sets of data points plotted against   > some x axis of > data, and you can draw a line on the graph connecting each set of   > data points. > > For example: > > A               B              C          D > 0.6566        2.1185        1.2320        5 > 0.647         2.0865        1.2325        10 > 0.6532        2.1060        1.2287        15 > 0.6487        2.1290        1.2313        20 > 0.6594        2.1285        1.2341        25 > 0.6577        2.1070        1.2343        30 > 0.6579        2.1345        1.2340        35 > 0.6734        2.1705        1.2362        40 > 0.675         2.1845        1.2372        45 > 0.6592        2.1550        1.2340        50 > 0.6647        2.1710        1.2305        55 > > > > Would there be a way: > a) To graph all the points of data in sets A, B and C as Y   > coordinates on one > graph, using the points in set D as the X-axis/coordinates for all   > 3 sets (A, B > and C)? > b) To be able to draw 3 lines on the graph that connect each set of   > data (1 line > connects all the A points, one line connects all the B points, one   > line connects > all the C points) > > > I couldn't find anything in the examples or the help section about   > multiple > lines on the same graph, only one line. ?points ?lines ?matplot ###################################################################### Attention:\ This e-mail message is privileged and confidenti...{{dropped}} ______________________________________________ [hidden email] mailing list https://stat.ethz.ch/mailman/listinfo/r-helpPLEASE do read the posting guide http://www.R-project.org/posting-guide.htmland provide commented, minimal, self-contained, reproducible code.
Open this post in threaded view
|

## Re: Line Graph - Greater than 2 variables on plot

 In reply to this post by Wayne Aldo Gavioli This should do it for you: > x <- read.table(textConnection("A               B              C          D + 0.6566        2.1185        1.2320        5 + 0.647         2.0865        1.2325        10 + 0.6532        2.1060        1.2287        15 + 0.6487        2.1290        1.2313        20 + 0.6594        2.1285        1.2341        25 + 0.6577        2.1070        1.2343        30 + 0.6579        2.1345        1.2340        35 + 0.6734        2.1705        1.2362        40 + 0.675         2.1845        1.2372        45 + 0.6592        2.1550        1.2340        50 + 0.6647        2.1710        1.2305        55"), header=TRUE) > > matplot(x[, 4], x[, -4], type='o') > On 9/20/07, Wayne Aldo Gavioli <[hidden email]> wrote: > > > Hello all, > > I was wondering if anyone knew how to construct a multiple line graph on R, > where there are 2 (or more) sets of data points plotted against some x axis of > data, and you can draw a line on the graph connecting each set of data points. > > For example: > > A               B              C          D > 0.6566        2.1185        1.2320        5 > 0.647         2.0865        1.2325        10 > 0.6532        2.1060        1.2287        15 > 0.6487        2.1290        1.2313        20 > 0.6594        2.1285        1.2341        25 > 0.6577        2.1070        1.2343        30 > 0.6579        2.1345        1.2340        35 > 0.6734        2.1705        1.2362        40 > 0.675         2.1845        1.2372        45 > 0.6592        2.1550        1.2340        50 > 0.6647        2.1710        1.2305        55 > > > > Would there be a way: > a) To graph all the points of data in sets A, B and C as Y coordinates on one > graph, using the points in set D as the X-axis/coordinates for all 3 sets (A, B > and C)? > b) To be able to draw 3 lines on the graph that connect each set of data (1 line > connects all the A points, one line connects all the B points, one line connects > all the C points) > > > I couldn't find anything in the examples or the help section about multiple > lines on the same graph, only one line. > > > Thanks, > > > > Wayne > > ______________________________________________ > [hidden email] 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. > -- Jim Holtman Cincinnati, OH +1 513 646 9390 What is the problem you are trying to solve? ______________________________________________ [hidden email] mailing list https://stat.ethz.ch/mailman/listinfo/r-helpPLEASE do read the posting guide http://www.R-project.org/posting-guide.htmland provide commented, minimal, self-contained, reproducible code.
Open this post in threaded view
|

## Re: Line Graph - Greater than 2 variables on plot

 In reply to this post by Wayne Aldo Gavioli Wayne Aldo Gavioli wrote: > > Hello all, > > I was wondering if anyone knew how to construct a multiple line graph on R, > where there are 2 (or more) sets of data points plotted against some x axis of > data, and you can draw a line on the graph connecting each set of data points. > > For example: > > A               B              C          D > 0.6566        2.1185        1.2320        5 > 0.647         2.0865        1.2325        10 > 0.6532        2.1060        1.2287        15 > 0.6487        2.1290        1.2313        20 > 0.6594        2.1285        1.2341        25 > 0.6577        2.1070        1.2343        30 > 0.6579        2.1345        1.2340        35 > 0.6734        2.1705        1.2362        40 > 0.675         2.1845        1.2372        45 > 0.6592        2.1550        1.2340        50 > 0.6647        2.1710        1.2305        55 > > > > Would there be a way: > a) To graph all the points of data in sets A, B and C as Y coordinates on one > graph, using the points in set D as the X-axis/coordinates for all 3 sets (A, B > and C)? > b) To be able to draw 3 lines on the graph that connect each set of data (1 line > connects all the A points, one line connects all the B points, one line connects > all the C points) > > > I couldn't find anything in the examples or the help section about multiple > lines on the same graph, only one line. > Hi Wayne, Assume your data is in a data frame named "wag": plot(wag\$D,wag\$A,main="Three variable plot",xlab="D",ylab="Value",   ylim=range(wag[c("A","B","C")]),type="l",col=2) lines(wag\$D,wag\$B,type="l",pch=2,col=3) lines(wag\$D,wag\$C,type="l",pch=3,col=4) legend(25,1.9,c("A","B","C"),lty=1,col=2:4) Jim ______________________________________________ [hidden email] mailing list https://stat.ethz.ch/mailman/listinfo/r-helpPLEASE do read the posting guide http://www.R-project.org/posting-guide.htmland provide commented, minimal, self-contained, reproducible code.
Open this post in threaded view
|

## Re: Line Graph - Greater than 2 variables on plot

 You can also use the facilities in the lattice package.  Using Jim´s data names: require(lattice) xyplot(A+B+C~D, data=wag, type="l", auto.key=list(points = FALSE, lines = TRUE, space = "bottom"), ylab="value", main="Three variable plot") Regards, Francisco Jim Lemon wrote: > Wayne Aldo Gavioli wrote: >> Hello all, >> >> I was wondering if anyone knew how to construct a multiple line graph on R, >> where there are 2 (or more) sets of data points plotted against some x axis of >> data, and you can draw a line on the graph connecting each set of data points. >> >> For example: >> >> A               B              C          D >> 0.6566        2.1185        1.2320        5 >> 0.647         2.0865        1.2325        10 >> 0.6532        2.1060        1.2287        15 >> 0.6487        2.1290        1.2313        20 >> 0.6594        2.1285        1.2341        25 >> 0.6577        2.1070        1.2343        30 >> 0.6579        2.1345        1.2340        35 >> 0.6734        2.1705        1.2362        40 >> 0.675         2.1845        1.2372        45 >> 0.6592        2.1550        1.2340        50 >> 0.6647        2.1710        1.2305        55 >> >> >> >> Would there be a way: >> a) To graph all the points of data in sets A, B and C as Y coordinates on one >> graph, using the points in set D as the X-axis/coordinates for all 3 sets (A, B >> and C)? >> b) To be able to draw 3 lines on the graph that connect each set of data (1 line >> connects all the A points, one line connects all the B points, one line connects >> all the C points) >> >> >> I couldn't find anything in the examples or the help section about multiple >> lines on the same graph, only one line. >> > Hi Wayne, > > Assume your data is in a data frame named "wag": > > plot(wag\$D,wag\$A,main="Three variable plot",xlab="D",ylab="Value", >   ylim=range(wag[c("A","B","C")]),type="l",col=2) > lines(wag\$D,wag\$B,type="l",pch=2,col=3) > lines(wag\$D,wag\$C,type="l",pch=3,col=4) > legend(25,1.9,c("A","B","C"),lty=1,col=2:4) > > Jim > > ______________________________________________ > [hidden email] 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. > ______________________________________________ [hidden email] mailing list https://stat.ethz.ch/mailman/listinfo/r-helpPLEASE do read the posting guide http://www.R-project.org/posting-guide.htmland provide commented, minimal, self-contained, reproducible code.
Open this post in threaded view
|

## Re: Line Graph - Greater than 2 variables on plot

 Or with a little data manipulation, in ggplot2: library(ggplot2) qplot(D, value, data=melt(wag, m="D"), colour=variable, geom="line") Hadley On 9/21/07, Francisco J. Zagmutt <[hidden email]> wrote: > You can also use the facilities in the lattice package.  Using Jim´s > data names: > > require(lattice) > xyplot(A+B+C~D, data=wag, type="l", auto.key=list(points = FALSE, lines > = TRUE, space = "bottom"), ylab="value", main="Three variable plot") > > Regards, > > Francisco > > > Jim Lemon wrote: > > Wayne Aldo Gavioli wrote: > >> Hello all, > >> > >> I was wondering if anyone knew how to construct a multiple line graph on R, > >> where there are 2 (or more) sets of data points plotted against some x axis of > >> data, and you can draw a line on the graph connecting each set of data points. > >> > >> For example: > >> > >> A               B              C          D > >> 0.6566        2.1185        1.2320        5 > >> 0.647         2.0865        1.2325        10 > >> 0.6532        2.1060        1.2287        15 > >> 0.6487        2.1290        1.2313        20 > >> 0.6594        2.1285        1.2341        25 > >> 0.6577        2.1070        1.2343        30 > >> 0.6579        2.1345        1.2340        35 > >> 0.6734        2.1705        1.2362        40 > >> 0.675         2.1845        1.2372        45 > >> 0.6592        2.1550        1.2340        50 > >> 0.6647        2.1710        1.2305        55 > >> > >> > >> > >> Would there be a way: > >> a) To graph all the points of data in sets A, B and C as Y coordinates on one > >> graph, using the points in set D as the X-axis/coordinates for all 3 sets (A, B > >> and C)? > >> b) To be able to draw 3 lines on the graph that connect each set of data (1 line > >> connects all the A points, one line connects all the B points, one line connects > >> all the C points) > >> > >> > >> I couldn't find anything in the examples or the help section about multiple > >> lines on the same graph, only one line. > >> > > Hi Wayne, > > > > Assume your data is in a data frame named "wag": > > > > plot(wag\$D,wag\$A,main="Three variable plot",xlab="D",ylab="Value", > >   ylim=range(wag[c("A","B","C")]),type="l",col=2) > > lines(wag\$D,wag\$B,type="l",pch=2,col=3) > > lines(wag\$D,wag\$C,type="l",pch=3,col=4) > > legend(25,1.9,c("A","B","C"),lty=1,col=2:4) > > > > Jim > > > > ______________________________________________ > > [hidden email] 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. > > > > ______________________________________________ > [hidden email] 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. > -- http://had.co.nz/______________________________________________ [hidden email] mailing list https://stat.ethz.ch/mailman/listinfo/r-helpPLEASE do read the posting guide http://www.R-project.org/posting-guide.htmland provide commented, minimal, self-contained, reproducible code.