Dear R-help list, I'm trying to overlay a number of data objects in a plot. Following an earlier example on the list I've created an empty plot as follows> xlim <- range(as.numeric(c("0","10000"))) > ylim <- range(as.numeric(c("0","25")) ) > plot(NA, xlim=xlim, ylim=ylim, xlab="distance", ylab="semivariance")However when I try to plot something on it, I get the following error:> points(v[2],v[3])Error in as.double.default(x) : (list) object cannot be coerced to double A sample of my data looks like the following V[2]: gamma 1 0.040000 2 0.582500 3 1.574545 4 7.126500 ..... and V[3]: dist 1 470.0426 2 1045.6365 3 1607.1936 .... Does anyone have any idea how to fix this? Thanks very much, femke [[alternative HTML version deleted]]
Brilliant! Why the double brackets though? thanks femke ----- Original Message ----- From: <james.holtman at convergys.com> To: "femke" <femke at geog.umd.edu> Sent: Wednesday, February 18, 2004 1:58 PM Subject: Re: [R] overlay points on plot> > > > > have you tried: > > points(v[[2]],v[[3]]) > __________________________________________________________ > James Holtman "What is the problem you are trying to solve?" > Executive Consultant -- Office of Technology, Convergys > james.holtman at convergys.com > +1 (513) 723-2929 > > > > "femke" > <femke at geog.umd.edu> To:<r-help at stat.math.ethz.ch>> Sent by: cc: > r-help-bounces at stat.m Subject: [R] overlaypoints on plot> ath.ethz.ch > > > 02/18/2004 13:03 > > > > > > > > Dear R-help list, > > I'm trying to overlay a number of data objects in a plot. Following an > earlier example on the list I've created an empty plot as follows > > > xlim <- range(as.numeric(c("0","10000"))) > > ylim <- range(as.numeric(c("0","25")) ) > > plot(NA, xlim=xlim, ylim=ylim, xlab="distance", ylab="semivariance") > > However when I try to plot something on it, I get the following error: > > > points(v[2],v[3]) > Error in as.double.default(x) : (list) object cannot be coerced to double > > A sample of my data looks like the following V[2]: > > gamma > 1 0.040000 > 2 0.582500 > 3 1.574545 > 4 7.126500 > ..... > > and V[3]: > > dist > 1 470.0426 > 2 1045.6365 > 3 1607.1936 > .... > > > Does anyone have any idea how to fix this? > > Thanks very much, > > femke > [[alternative HTML version deleted]] > > ______________________________________________ > R-help at stat.math.ethz.ch mailing list > https://www.stat.math.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide! > http://www.R-project.org/posting-guide.html > > >
Is v a data frame? In that case you need v[[2]] and v[[3]], as v[2] is a data frame. On Wed, 18 Feb 2004, femke wrote:> > Dear R-help list, > > I'm trying to overlay a number of data objects in a plot. Following an earlier example on the list I've created an empty plot as follows > > > xlim <- range(as.numeric(c("0","10000"))) > > ylim <- range(as.numeric(c("0","25")) ) > > plot(NA, xlim=xlim, ylim=ylim, xlab="distance", ylab="semivariance") > > However when I try to plot something on it, I get the following error: > > > points(v[2],v[3]) > Error in as.double.default(x) : (list) object cannot be coerced to double > > A sample of my data looks like the following V[2]: > > gamma > 1 0.040000 > 2 0.582500 > 3 1.574545 > 4 7.126500 > ..... > > and V[3]: > > dist > 1 470.0426 > 2 1045.6365 > 3 1607.1936 > .... > > > Does anyone have any idea how to fix this? > > Thanks very much, > > femke > [[alternative HTML version deleted]] > > ______________________________________________ > R-help at stat.math.ethz.ch mailing list > https://www.stat.math.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html > >-- Brian D. Ripley, ripley at stats.ox.ac.uk Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/ University of Oxford, Tel: +44 1865 272861 (self) 1 South Parks Road, +44 1865 272866 (PA) Oxford OX1 3TG, UK Fax: +44 1865 272595
In a message dated 2/18/2004 10:13:53 AM Pacific Standard Time, femke at geog.umd.edu writes:>Dear R-help list, > >I'm trying to overlay a number of data objects in a plot. Following anearlier example on the >list I've created an empty plot as follows> >> xlim <- range(as.numeric(c("0","10000"))) >> ylim <- range(as.numeric(c("0","25")) ) >> plot(NA, xlim=xlim, ylim=ylim, xlab="distance", ylab="semivariance") > >However when I try to plot something on it, I get the following error: > >> points(v[2],v[3]) >Error in as.double.default(x) : (list) object cannot be coerced to doubleTry points(v[, 2], v[, 3]) ? Dan Nordlund
The solution is found in help("Subscript"). The subscripting you show inside the function points() returns a data frame of one column. This is indeed a list and not a vector. There are several ways to subscript a data frame that will return one column as a vector. If you use one of them, this should all work. The 40 page document "An Introduction to R" may also be helpful. In other words, this is pretty thoroughly covered in the documentation. - tom blackwell - u michigan medical school - ann arbor - On Wed, 18 Feb 2004, femke wrote:> > Dear R-help list, > > I'm trying to overlay a number of data objects in a plot. Following an earlier example on the list I've created an empty plot as follows > > > xlim <- range(as.numeric(c("0","10000"))) > > ylim <- range(as.numeric(c("0","25")) ) > > plot(NA, xlim=xlim, ylim=ylim, xlab="distance", ylab="semivariance") > > However when I try to plot something on it, I get the following error: > > > points(v[2],v[3]) > Error in as.double.default(x) : (list) object cannot be coerced to double > > A sample of my data looks like the following V[2]: > > gamma > 1 0.040000 > 2 0.582500 > 3 1.574545 > 4 7.126500 > ..... > > and V[3]: > > dist > 1 470.0426 > 2 1045.6365 > 3 1607.1936 > .... > > > Does anyone have any idea how to fix this? > > Thanks very much, > > femke > [[alternative HTML version deleted]] > > ______________________________________________ > R-help at stat.math.ethz.ch mailing list > https://www.stat.math.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html >
What do you get from the following: class(v) class(v[2]) If class(v) is "list", then class(v[2]) will also be "list". In that case try the following: points(v[[2]],v[[3]]) hope this helps. spencer graves femke wrote:>Dear R-help list, > >I'm trying to overlay a number of data objects in a plot. Following an earlier example on the list I've created an empty plot as follows > > > >>xlim <- range(as.numeric(c("0","10000"))) >>ylim <- range(as.numeric(c("0","25")) ) >>plot(NA, xlim=xlim, ylim=ylim, xlab="distance", ylab="semivariance") >> >> > >However when I try to plot something on it, I get the following error: > > > >>points(v[2],v[3]) >> >> >Error in as.double.default(x) : (list) object cannot be coerced to double > >A sample of my data looks like the following V[2]: > > gamma >1 0.040000 >2 0.582500 >3 1.574545 >4 7.126500 >..... > >and V[3]: > > dist >1 470.0426 >2 1045.6365 >3 1607.1936 >.... > > >Does anyone have any idea how to fix this? > >Thanks very much, > >femke > [[alternative HTML version deleted]] > >______________________________________________ >R-help at stat.math.ethz.ch mailing list >https://www.stat.math.ethz.ch/mailman/listinfo/r-help >PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html > >