[R] contour lines intersect

Ross Ihaka ihaka at r-project.org
Wed Aug 6 10:00:36 CEST 2003


Adrian Baddeley wrote:
> Hi,
> 
> Sorry if this is already known...
> 
> contour() sometimes draws contour lines that intersect.
> Is there a temporary fix?
> 
> A dataset which causes problems is at
>    http://www.maths.uwa.edu.au/~adrian/dumpdata.R
> If you try just
>    source("dumpdata.R")
>    image(huh)
>    contour(huh)
> the 100 x 100 matrix 'huh' contains an hourglass-shaped region
> of values around 0.8. The contour plot shows two contour lines at
> the level 0.8 which cross each other in a figure 8.
> 
> In the short term can anyone suggest how to fix the contour plot
> for this particular dataset??

A close look suggests that the lines don't actually cross -- e.g. try

	contour(huh, xlim = c(0.82, 0.88), ylim = c(0.1, 0.12))

The handling of the "crossing case" in R is an implementation of that in 
Cleveland's "Visualizing Data" (one of the "for-the-record" sections). 
I don't think the algorithm permits crossings.

-- 
Ross Ihaka                         Email:  ihaka at r-project.org
The R Project and R Foundation




More information about the R-help mailing list