[R] Line Graph - Greater than 2 variables on plot

Jim Porzak jporzak at gmail.com
Sat Sep 22 00:52:02 CEST 2007


Hi Hadley,

I'm trying your suggestion to Wayne. Did you mean to say:

qplot(D, value, data = melt(wag), colour = variable, geom = "line")
?

With the m="D" argument, I get the error:
Error in as.data.frame.default(x[[i]], optional = TRUE) :
	cannot coerce class "function" into a data.frame

-- 
Best,
Jim Porzak
Responsys, Inc.
San Francisco, CA
http://www.linkedin.com/in/jimporzak

On 9/21/07, hadley wickham <h.wickham at gmail.com> wrote:
> 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 <gerifalte28 at hotmail.com> 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
> > >
> > > ______________________________________________
> > > 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.
> > >
> >
> > ______________________________________________
> > 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.
> >
>
>
> --
> http://had.co.nz/
>
> ______________________________________________
> 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.
>



More information about the R-help mailing list