Hi, I am trying to plot the following data such that both variable y and z vs x. (ie two lines on a single plot). As the x variable is not numeric, how do I go about it? Appreciate if any expert could help. I know I use plot() follow by lines() to add another line to the plot. But my problem is i was unable to plot y vs x in the first place. x y z D9S1820 1.487983031 0.86998805 9_16.0 1.487983031 0.86998805 D9S1796 1.585360853 1.233512794 9_18.0 1.585360853 1.233512794 D9S1815 2.683400698 2.064643907 9_20.0 2.683400698 2.064643907 D9S1689 3.02200219 2.154777894 KG1617293.209574083 2.436400271 9_22.0 3.209574083 2.436400271 D9S1816 3.615467385 2.695294102 9_24.0 3.615467385 2.695294102 D9S1786 3.787546039 3.300248968 D9S180 3.297311032 3.264321274 D9S1857 2.704872915 2.894489815 9_26.0 2.704872915 2.894489815 D9S1690 1.880744111 2.386263859 9_28.0 1.880744111 2.386263859 D9S271 1.085762652 1.483861423 9_30.0 1.085762652 1.483861423 D9S938 1.191451449 1.417255034 D9S1866 1.235450281 1.439973751 9_32.0 1.235450281 1.439973751 9_34.0 1.235450281 1.439973751 9_36.0 1.235450281 1.439973751 D9S1677 0.455188088 0.598254918 9_38.0 0.455188088 0.598254918 D9S930 0.56082526 0.562725203 Thanks J -- View this message in context: http://www.nabble.com/Plotting-Two-Lines-tp21637287p21637287.html Sent from the R help mailing list archive at Nabble.com.
stats787 wrote:> Hi, > > I am trying to plot the following data such that both variable y and z vs x. > (ie two lines on a single plot). As the x variable is not numeric, how do I > go about it? Appreciate if any expert could help. > I know I use plot() follow by lines() to add another line to the plot. But > my problem is i was unable to plot y vs x in the first place. >Hi stats787, I think this is a replay of a previous problem where the sender expected the values on the abcissa to be sorted before plotting. You have the additional camoflage of a factor as that set of values. One minor problem is that the separator is missing between elements 1 and 2 in the eighth line. After fixing that, try this (assuming your data frame is named "stats787": plot(as.numeric(stats787$x)[order(stats787$x)],stats787$y,type="l",col="red") lines(as.numeric(stats787$x)[order(stats787$x)],stats787$z,col="green") Jim
Jim Lemon wrote:> stats787 wrote: >> Hi, >> >> I am trying to plot the following data such that both variable y and >> z vs x. >> (ie two lines on a single plot). As the x variable is not numeric, >> how do I >> go about it? Appreciate if any expert could help. I know I use plot() >> follow by lines() to add another line to the plot. But >> my problem is i was unable to plot y vs x in the first place. >> > Hi stats787, > I think this is a replay of a previous problem where the sender > expected the values on the abcissa to be sorted before plotting. You > have the additional camoflage of a factor as that set of values. One > minor problem is that the separator is missing between elements 1 and > 2 in the eighth line. After fixing that, try this (assuming your data > frame is named "stats787": > > plot(as.numeric(stats787$x)[order(stats787$x)],stats787$y,type="l",col="red") > > lines(as.numeric(stats787$x)[order(stats787$x)],stats787$z,col="green") >Oops, that should be: plot(as.numeric(stats787$x)[order(stats787$x)],stats787$y[order(stats787$x)], type="l",col="red") lines(as.numeric(stats787$x)[order(stats787$x)],stats787$z[order(stats787$x)], col="green") Jim