[R] connecting points into a smooth curve

Gavin Simpson gavin.simpson at ucl.ac.uk
Mon Nov 1 14:47:53 CET 2010


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
%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%



More information about the R-help mailing list