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,

-- 
Gregory (Greg) L. Snow Ph.D.
Statistical Data Center
Intermountain Healthcare
greg.s...@imail.org
801.408.8111


> -----Original Message-----
> From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-
> project.org] On Behalf Of Andrea Storto
> Sent: Tuesday, January 06, 2009 9:52 AM
> To: r-help@r-project.org
> Subject: [R] smoothed contour lines
> 
> Hi all,
> 
> I'm trying to draw a contour plot
> with rounded (smoothed) contour lines instead of sharp angles;
> when the grid consists of only a few points
> in x- and y- axis, the resulting contour
> is in facts rather ugly since very sharp angles may appear.
> 
> I did not find any way to do it,
> by using either "contour" or "contourplot" (from the lattice package),
> I wonder if there exist a way for smoothing the angles,
> apart from artificially increasing the grid resolution,
> 
> Thanks in advance
> 
> Andrea
> 
> ______________________________________________
> R-help@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@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.

Reply via email to