[R] Smooth contour of a map

Duncan Murdoch murdoch.duncan at gmail.com
Tue May 17 13:05:48 CEST 2011


On 11-05-17 5:58 AM, Pierre Bruyer wrote:
> I'm a French developer (so I am sorry if my english is not perfect). I have a problem to smooth the contours of a map. I have a dataset with 3 columns, x, y and z, where x and y are the coordinates of my points and z is evaluate to a qualitative elevation and his representation is a set of colors, which is define by levels.
>
> The problem is the curve of my contour is so linear, and I would like a more continuous contour. I use the function fitted.contour to draw my map.

If you use a finer grid of x,y values you'll get shorter segments and 
they will look smoother.

You might be able to use a smooth interpolator (e.g. spline()) rather 
than linear interpolation, but those occasionally do strange things e.g.

x <- c(1:4, 5.9, 6:10)
y <- c(1:4,   7, 6:10)
plot(spline(x,y, n=200), type="l")
points(x,y)

where one point is out of line with the others, but the curve 
overcompensates in order to stay smooth.

Duncan Murdoch



More information about the R-help mailing list