If I have, say, five scatter points and want to connect them together into a smooth curve. I did plot(x,y,type="l"), but the graph is five segments connecting with each other, but not a smooth curve. I wonder if there is a line type that is a curve. Thanks! -- View this message in context: http://r.789695.n4.nabble.com/connecting-points-into-a-smooth-curve-tp3021796p3021796.html Sent from the R help mailing list archive at Nabble.com.
Hi r-help-bounces at r-project.org napsal dne 01.11.2010 07:18:47:> > If I have, say, five scatter points and want to connect them togetherinto a> smooth curve.As you are not much specific about what you consider "smooth curve" here are some options use some model ?lm and plot predicted values with line ??smooth will give you many functions for smoothing data e.g. ?loess ?supsmu ?spline and some others Regards Petr> I did plot(x,y,type="l"), but the graph is five segments connecting with > each other, but not a smooth curve. > I wonder if there is a line type that is a curve. Thanks! > > > -- > View this message in context:http://r.789695.n4.nabble.com/connecting-points-> into-a-smooth-curve-tp3021796p3021796.html > Sent from the R help mailing list archive at Nabble.com. > > ______________________________________________ > R-help at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guidehttp://www.R-project.org/posting-guide.html> and provide commented, minimal, self-contained, reproducible code.
----------------------------------------> To: kaiyan at berkeley.edu > From: petr.pikal at precheza.cz > Date: Mon, 1 Nov 2010 11:50:17 +0100 > CC: r-help at r-project.org > Subject: [R] Odp: connecting points into a smooth curve > > Hi > > r-help-bounces at r-project.org napsal dne 01.11.2010 07:18:47: > > > > > If I have, say, five scatter points and want to connect them together > into a > > smooth curve. > > As you are not much specific about what you consider "smooth curve" here > are some optionsI think the OP said he had 5 points so that leaves a lot to the imagination. Presumably smooth means something like, " a curve that goes through all 5 points and has as many continuous derivatives as possible." So you write a general fitting function, Taylor would be a good expansion I suppose, impose the above conditions, and see if there is an R package that provides the coefficients you want? Someone else was asking a related question and there I offered sinc interpolation and indeed this can be exact given a band limited signal and no time base errors etc. Doing much of anything meaningful with 5 points would probably require a model as the other poster suggested- your model would need to be solved depending on its particulars. You sometimes see these kinds of wild interpolation issues with the drawing programs and free-form input "smoothing" where it tries to fit a smooth curve to your mouse moves.> > use some model ?lm and plot predicted values with line > ??smooth will give you many functions for smoothing data e.g. > ?loess > ?supsmu > ?spline > and some others > > Regards > Petr > > > I did plot(x,y,type="l"), but the graph is five segments connecting with > > each other, but not a smooth curve.[[elided Hotmail spam]]> > > > > > -- > > View this message in context: > http://r.789695.n4.nabble.com/connecting-points- > > into-a-smooth-curve-tp3021796p3021796.html > > Sent from the R help mailing list archive at Nabble.com. > > > > ______________________________________________ > > 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.
Hi r-help-bounces at r-project.org napsal dne 01.11.2010 13:02:46:> > > > > > > ---------------------------------------- > > To: kaiyan at berkeley.edu > > From: petr.pikal at precheza.cz > > Date: Mon, 1 Nov 2010 11:50:17 +0100 > > CC: r-help at r-project.org > > Subject: [R] Odp: connecting points into a smooth curve > > > > Hi > > > > r-help-bounces at r-project.org napsal dne 01.11.2010 07:18:47: > > > > > > > > If I have, say, five scatter points and want to connect themtogether> > into a > > > smooth curve. > > > > As you are not much specific about what you consider "smooth curve"here> > are some options > > > I think the OP said he had 5 points so that leaves a lot to theimagination.> Presumably smooth means something like, " a curve that goes through all5 points> and has as many continuous derivatives as possible." So you write ageneral> fitting function, Taylor would be a good expansion I suppose, impose > the above conditions, and see if there > is an R package that provides the coefficients you want? > Someone else was asking a related question and there I offered sincinterpolation> and indeed this can be exact given a band limited signal and no timebase errors etc.> > > Doing much of anything meaningful with 5 points would probably require amodel> as the other > poster suggested- your model would need to be solved depending on itsparticulars.> > You sometimes see these kinds of wild interpolation issues with thedrawing> programs and free-form input "smoothing" where it tries to fit a smoothcurve> to your mouse moves.And of course in Excel graphs you can find something like "smooth" connection to points. Therefore the method depends on what the OP means by smooth curve. Regards Petr> > > > > > use some model ?lm and plot predicted values with line > > ??smooth will give you many functions for smoothing data e.g. > > ?loess > > ?supsmu > > ?spline > > and some others > > > > Regards > > Petr > > > > > I did plot(x,y,type="l"), but the graph is five segments connectingwith> > > each other, but not a smooth curve. > [[elided Hotmail spam]] > > > > > > > > > -- > > > View this message in context: > > http://r.789695.n4.nabble.com/connecting-points- > > > into-a-smooth-curve-tp3021796p3021796.html > > > Sent from the R help mailing list archive at Nabble.com. > > > > > > ______________________________________________ > > > 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 guidehttp://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 guidehttp://www.R-project.org/posting-guide.html> and provide commented, minimal, self-contained, reproducible code.
?>> > > > Doing much of anything meaningful with 5 points would probably require a > model > > as the other > > poster suggested- your model would need to be solved depending on its > particulars. > > > > You sometimes see these kinds of wild interpolation issues with the > drawing > > programs and free-form input "smoothing" where it tries to fit a smooth > curve > > to your mouse moves. > > And of course in Excel graphs you can find something like "smooth" > connection to points. Therefore the method depends on what the OP means by > smooth curve. >I think some of these let you manually set various parameters too to make it look right - if the OP follows my advice,tries to define smooth in terms of something data-relevant probably related to properties of derivatives, he will probably get to a point where he can have more parameters than data and can set these things to suite his imagination or artistic inclinations :)> Regards > Petr >
On Sun, 2010-10-31 at 23:18 -0700, tooblue wrote:> If I have, say, five scatter points and want to connect them together into a > smooth curve. > I did plot(x,y,type="l"), but the graph is five segments connecting with > each other, but not a smooth curve. > I wonder if there is a line type that is a curve. Thanks!?spline would be one way of joining up the point with smooth curve passing through the 5 observations. However, as several other have noted, you need to explain how you want the smooth curve to pass through the observations. Here's an example: x <- 1:5 y <- rnorm(5) ylim <- with(sp, range(y)) plot(x,y, ylim = ylim) lines(sp, col = "red") HTH G -- %~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~% Dr. Gavin Simpson [t] +44 (0)20 7679 0522 ECRC, UCL Geography, [f] +44 (0)20 7679 0565 Pearson Building, [e] gavin.simpsonATNOSPAMucl.ac.uk Gower Street, London [w] http://www.ucl.ac.uk/~ucfagls/ UK. WC1E 6BT. [w] http://www.freshwaters.org.uk %~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%
In addition to the other responses you have received, the xspline function may also be of use. -- Gregory (Greg) L. Snow Ph.D. Statistical Data Center Intermountain Healthcare greg.snow at imail.org 801.408.8111> -----Original Message----- > From: r-help-bounces at r-project.org [mailto:r-help-bounces at r- > project.org] On Behalf Of tooblue > Sent: Monday, November 01, 2010 12:19 AM > To: r-help at r-project.org > Subject: [R] connecting points into a smooth curve > > > If I have, say, five scatter points and want to connect them together > into a > smooth curve. > I did plot(x,y,type="l"), but the graph is five segments connecting > with > each other, but not a smooth curve. > I wonder if there is a line type that is a curve. Thanks! > > > -- > View this message in context: http://r.789695.n4.nabble.com/connecting- > points-into-a-smooth-curve-tp3021796p3021796.html > Sent from the R help mailing list archive at Nabble.com. > > ______________________________________________ > 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.