Dear R Users, I have a data frame of the nature:> head(aggregate_1986)Latitude Mean Annual Simulated Runoff per 1? Latitudinal Band 1 -55 574.09287 2 -54 247.23078 3 -53 103.40756 4 -52 86.99991 5 -51 45.21980 6 -50 55.92928 Mean Annual Observed Runoff per 1? Latitudinal Band 1 491.9525 2 319.6592 3 237.8222 4 179.5391 5 105.2968 6 136.6124 I am hoping to plot columns 2 and 3 against Latitude. I understand that you have to do this by plotting one column at a time, so I have been starting by attempting the following, but receiving errors:> plot(aggregate_1986[1] ~ aggregate_1986[2], type="l")Error in model.frame.default(formula = aggregate_1986[1] ~ aggregate_1986[2], : invalid type (list) for variable 'aggregate_1986[1]' Or...> plot(aggregate_1986[1],aggregate_1986[2], type="l")Error in stripchart.default(x1, ...) : invalid plotting method I'm obviously doing something fundamentally wrong (!). I'd be grateful for any suggestions as to how I should go about this. Many thanks, Steve
Steve Murray <smurray444 at hotmail.com> wrote> >I have a data frame of the nature:>I am hoping to plot columns 2 and 3 against Latitude. I understand that you have to do this by plotting one column at a time, so I have been starting by attempting the following, but receiving errors: > > >I'm obviously doing something fundamentally wrong (!). I'd be grateful for any suggestions as to how I should go about this. >I think what you are doing wrong is misinterpreting what people mean when they say "line". They don't mean line of data, they mean line on the plot. Does this get you started? lat <- seq(-55:-50) simrun <- c(574.09, 247.23, 103.41, 86.99, 45.22, 55.93) obsrun <- c(491.95, 319.66, 237.82, 179.54, 105.30, 136.61) plot(simrun~lat,type = 'l') lines(obsrun~lat) Peter Peter L. Flom, PhD Statistical Consultant www DOT peterflomconsulting DOT com
you might also look at matplot d=data.frame(x=1:10,y1=sort(rnorm(10)),y2=sort(rnorm(10))) matplot(d[,1],d[,2:3],type='l',lty=1:2) David Freedman Steve Murray-3 wrote:> > > Dear R Users, > > I have a data frame of the nature: > >> head(aggregate_1986) > Latitude Mean Annual Simulated Runoff per 1? Latitudinal Band > 1 -55 574.09287 > 2 -54 247.23078 > 3 -53 103.40756 > 4 -52 86.99991 > 5 -51 45.21980 > 6 -50 55.92928 > Mean Annual Observed Runoff per 1? Latitudinal Band > 1 491.9525 > 2 319.6592 > 3 237.8222 > 4 179.5391 > 5 105.2968 > 6 136.6124 > > > I am hoping to plot columns 2 and 3 against Latitude. I understand that > you have to do this by plotting one column at a time, so I have been > starting by attempting the following, but receiving errors: > >> plot(aggregate_1986[1] ~ aggregate_1986[2], type="l") > Error in model.frame.default(formula = aggregate_1986[1] ~ > aggregate_1986[2], : > invalid type (list) for variable 'aggregate_1986[1]' > > > Or... > > >> plot(aggregate_1986[1],aggregate_1986[2], type="l") > Error in stripchart.default(x1, ...) : invalid plotting method > > > I'm obviously doing something fundamentally wrong (!). I'd be grateful for > any suggestions as to how I should go about this. > > Many thanks, > > Steve > > > ______________________________________________ > 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. > >-- View this message in context: http://www.nabble.com/Problems-producing-a-simple-plot-tp23347296p23348181.html Sent from the R help mailing list archive at Nabble.com.