[R] extracting x,y coordinates from a contour plot

David Winsemius dwinsemius at comcast.net
Mon Sep 6 06:43:25 CEST 2010


On Sep 5, 2010, at 11:48 PM, Charles Annis, P.E. wrote:

> Requisite info: R version 2.11.1 (2010-05-31) running on a 64 bit HP  
> Windows
> 7 machine.
>
Doubt that makes much of a difference here.

> I have used contour() for several years.  Now I would like to  
> extract from a
> contour plot the x, y coordinates of a contour z=constant.  This  
> seems as
> though it would be straight-forward but I've been unsuccessful in my
> searches of CRAN.

Suggest you read the help page for contour and the pages to which it  
links as well as working the examples. The answer is illustrated in  
the examples on that page.

> Can anyone provide a hint?

 > x <- 10*1:nrow(volcano)
 > y <- 10*1:ncol(volcano)
 > xy160 <- contourLines(x, y, volcano, nlevels=1, levels=160)
 > str(xy160)
List of 2
  $ :List of 3
   ..$ level: num 160
   ..$ x    : num [1:165] 110 108 105 102 103 ...
   ..$ y    : num [1:165] 295 300 310 320 330 ...
  $ :List of 3
   ..$ level: num 160
   ..$ x    : num [1:31] 270 263 262 260 260 ...
   ..$ y    : num [1:31] 310 320 330 340 350 ...

-- 
David.

David Winsemius, MD
West Hartford, CT



More information about the R-help mailing list