Skip to content
Prev 166243 / 398502 Next

smoothed contour lines

Here is one possible approach to get you started (this is not a final answer):

x <- seq(-3,3)
y <- seq(-3,3)

z <- outer(x,y, function(x,y,...) x^2 + y^2 )

tmp <- contourLines(x,y,z)

contour(x,y,z, lty=0)
lapply(tmp, function(l) {
	x <- l$x
	y <- l$y
	if( length(x) > 2 ){
		if( isTRUE( all.equal( c(x[1],y[1]), c(x[length(x)],y[length(y)])))) {
			xspline(x[-1],y[-1], -1, FALSE)
		} else {
			xspline(x, y, -1, TRUE)
		}
	} else {
		lines(x,y) # or whatever else should go here
	}
} )


You can play with the settings to xspline to control the properties of the curves, also it will look better if you thin some of the points from contourLines (the points that are nearly identical cause the small loops).

Hope this helps,