I'm trying a bit of an experiment with polynomial curve fitting (don't worry, I wouldn't do this to actual data -- it's just a toy model for a specific question). When I generate a linear model of the data and plot it using plot(), everything works fine. But when I use plot(..., type="l") or lines(), I get an extra line connecting two points. How do I stop this from happening?
Here's the code: x = seq(-10, 10, by=0.1) data1poly <- 0.1*x + 0.2*x^2 + 0.3*x^3 + 0.4*x^4 + 0.5*x^5 + 0.6*x^6 + 0.7 + rnorm(length(x),1E-3, 1E-4) data2poly <- 0.1*x + 0.2*x^2 + 0.3*x^3 + 0.4*x^4 + 0.5*x^5 + 0.6*x^6 - 1 + rnorm(length(x), 1E-3, 1E-4) dataBoth.poly <- c(data1poly, data2poly) #Works well plot(c(x,x), predict(lm(dataBoth.poly ~ c(x,x) + I(c(x,x)^2)+I(c(x,x)^3)+I(c(x,x)^4)+I(c(x,x)^5)+I(c(x,x)^6)))) #Adds extra line plot(c(x,x), predict(lm(dataBoth.poly ~ c(x,x) + I(c(x,x)^2)+I(c(x,x)^3)+I(c(x,x)^4)+I(c(x,x)^5)+I(c(x,x)^6))), type="l") #or lines(c(x,x), predict(lm(dataBoth.poly ~ c(x,x) + I(c(x,x)^2)+I(c(x,x)^3)+I(c(x,x)^4)+I(c(x,x)^5)+I(c(x,x)^6)))) Thanks, Jane -- ------------- Jane Shevtsov Ecology Ph.D. candidate, University of Georgia co-founder, <www.worldbeyondborders.org> Check out my blog, <http://perceivingwholes.blogspot.com>Perceiving Wholes "The whole person must have both the humility to nurture the Earth and the pride to go to Mars." --Wyn Wachhorst, The Dream of Spaceflight _______________________________________________ R-sig-ecology mailing list R-sig-ecology@r-project.org https://stat.ethz.ch/mailman/listinfo/r-sig-ecology