[R] contour lines intersect
Roger Bivand
Roger.Bivand at nhh.no
Wed Aug 6 10:34:49 CEST 2003
On Wed, 6 Aug 2003, Ross Ihaka wrote:
> 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))
>
Or even:
contour(huh, levels=seq(0.75, 0.85, 0.001), xlim = c(0.82, 0.88),
ylim = c(0.1, 0.12))
- the data are very flat. It does look odd zoomed out, though - maybe
avoid the 0.8 contour by setting levels to something other than the
default? This looks OK:
image(huh, breaks = round(quantile(huh, prob = seq(0,1,0.1)), 2),
col = heat.colors(10))
contour(huh, levels = round(quantile(huh, prob = seq(0,1,0.1)),
digits = 2), drawlabels=FALSE, add=TRUE)
but obviously there are good reasons for the pretty() default levels.
filled.contour(huh, color.palette = rainbow, xlim = c(0.82, 0.88),
ylim = c(0.1, 0.12))
shows the same effect.
> 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.
>
>
--
Roger Bivand
Economic Geography Section, Department of Economics, Norwegian School of
Economics and Business Administration, Breiviksveien 40, N-5045 Bergen,
Norway. voice: +47 55 95 93 55; fax +47 55 95 93 93
e-mail: Roger.Bivand at nhh.no
More information about the R-help
mailing list