Re: [R] Beginner plot and map questions

From: Roger Bivand <>
Date: Sat 15 Oct 2005 - 19:38:45 EST

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

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

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:

> Hi,
> I have not been able to find answers to these questions in the FAQs,
> manuals, or R-help archives. If answers are available somewhere, please
> direct me to them.
> 1.) Is there a way to convert a table (e.g. represented as a data frame)
> to a function, specifying which columns are input and which column is
> output? It would seem that this would be useful for plotting
> experimental results, since e.g. contour(x, y, f) requires f to be a
> function.

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.

> 2.) If x is longitude and y is latitude, then I would think that
> contour(x, y, f) could be used to create a contour map with equally
> spaced latitude and longitude. And I've seen that the "maps" and
> "mapproj" packages can be used to create maps in different projections.
> a.) Once a base map is created and experimental data is projected to fit
> the base map, how is it added onto the map?

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.

> b.) Is there a way to combine the contouring and projection
> functionality to get contour maps in any of the supported projections?

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

> 3.) What algorithm is used by the contour() function? Are there any
> parameters that can be changed, such as radius of interest for a data
> point to affect a grid point?

Please see ?contour: Becker, R. A., Chambers, J. M. and Wilks, A. R. (1988) _The New S Language_. Wadsworth & Brooks/Cole; but see also:

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.

> Thanks for any help or references.
> ______________________________________________
> mailing list
> PLEASE do read the posting guide!

Roger Bivand
Economic Geography Section, Department of Economics, Norwegian School of
Economics and Business Administration, Helleveien 30, N-5045 Bergen,
Norway. voice: +47 55 95 93 55; fax +47 55 95 95 43

______________________________________________ mailing list
PLEASE do read the posting guide!
Received on Sat Oct 15 19:46:14 2005

This archive was generated by hypermail 2.1.8 : Sun 23 Oct 2005 - 18:55:07 EST