Skip to content
Prev 79069 / 398502 Next

Beginner plot and map questions

(OFF TOPIC) Although not mentioned in our exellent posting guide:

http://www.r-project.org/posting-guide.html

or Eric Raymond's excellent advice refered to in the posting guide:

http://www.catb.org/~esr/faqs/smart-questions.html

I personally often find it difficult to formulate a sensible reply to 
questions posted without a real user name and affiliation. I can 
appreciate that people posting to the list come from different generations 
and "cultures", and may not feel comfortable in saying who they are on the 
list.

I would, though, appeal to posters to give those who try to reply to 
questions at least a little help, by including an informative signature 
block. 

For want of a better name:

Dear Web User,
On Fri, 14 Oct 2005, Web User wrote:

            
You are not refering to the contour() method in the graphics package, 
which does not take an f= argument. Its third argument is z, which is a 
matrix of surface values on a grid. If your x and y vectors represent 
something other than required by the default contour() method, you must 
interpolate to such a grid first, for example using the interp() function 
in the akima package, or in some other way. As far as I am aware, R and 
contributed packages cannot compute contours directly from irregularly 
spaced (x,y,z) values. If your question relates to a contributed package, 
please say so.
It depends what kind of data, but note that the map() function in the maps 
package plots in coordinates transformed to the plotting device when 
projection is used. Without projection, map() plots and returns long/lat 
coordinates, but note that the y axis is stretched in relation to the x 
axis depending on the mean latitude of the map.
Using the contourLines() function, you can extract the lines in the 
coordinates given by the x and y grid sequences. You can also in principle 
project them too, and will be able to co-register them on the plot made by 
map(). 

If you are not bound to use the maps package for plotting and projection,
I would suggest that you look at the sp package on CRAN, and the spproj
and spmaps packages on http://r-spatial.sourceforge.net/R as a possible
alternatives. Then you can access coastline data from maps, convert
contourLines() output to a SpatialLinesDataFrame with the sp function
contourLines2SLDF(), and project both using the transform() methods in
spproj (after setting the correct projection strings for the spatial
objects).
Please see ?contour: Becker, R. A., Chambers, J. M. and Wilks, A. R. 
(1988) _The New S Language_. Wadsworth & Brooks/Cole; but see also:

http://finzi.psych.upenn.edu/R/Rhelp02a/archive/12366.html

in which Ross Ihaka writes:

"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."

which seems authoritative, of course, the code is the complete 
documentation.