[R] help to make a map on R

Ott Toomet siim at obs.ee
Thu Oct 3 09:43:46 CEST 2002


On Wed, 2 Oct 2002, Ronaldo Reis Jr. wrote:

  |Hi all,
  |I need a little help for construct an state's map on R.

I strongly recommend to take a look at package maps
(ftp://ftp.mcs.vuw.ac.nz/pub/statistics/map/), as suggested before.  It
includes maps of US (states and counties), UK (counties), New-Zealand and
China.  A pretty good descritption can be found at ,,Constructing a
geographical database'' by Richard Becker nad Allan Wilks, it is available
at web.

The problem in your case seem to be that you have not defined polylines and
polygons as are needed for the map() function.  Basically, the database
needs the definitions of line segments (borders, coastlines etc.), one
definition for one line.  Therafter you need definitions of polugons
(administrative units, lakes, cities...) desrcribed by the line segments
above.  And last, you need names for each of the polygon (you may be happy
with dummy names only).  From your description it seems to me that you don't
have descriptions of polygons.  If you have copirighted data, it is perhaps
not worth of so much work, but it depends on how much polyugons do you have.

----

If you don't want to use the package, I would suggest something following:

  |I have a datafile of longitude and latitude in the follow format:
  |
  |trajectory	latitude	longtude
  |T		-22.045618	-51.287056
  |T		-22.067078	-51.265888
  |T		-22.067039	-51.207249
  |
  |T		-22.059690	-48.089695
  |T		-22.075529	-48.074608
  |T		-22.072460	-48.044472
  |
  |T		-22.062767	-48.298473

I would perhaps use perl to transform the original file to a new one where I
give unique name for every trajectory (you may let me know if you are not
familiar with perl).

  |To read a file is simple, but I need that R change the value of
  |trajectory after a blank line, reading something like this:
  |
  |trajectory	latitude	longitude
  |T1		-22.045618	-51.287056
  |T1		-22.067078	-51.265888
  |T1		-22.067039	-51.207249
  |T2		-22.059690	-48.089695
  |T2		-22.075529	-48.074608

...

  |tapply() for separate the coordinates for each trajectory, something like 
  |this:
  |
  |> longitude <- tapply(longitude,trajectory,c)
  |> latitude <- tapply(latitude,trajectory,c)
  |The nest step is to make a plot with the coordinates.
  |
  |> plot(longitude,latitude, asp = 1, type = "n")

What about (not tested)

plot(1:2, xlim=range(unlist(longitude)), ylim=range(unlist(latitude)),
type="n")
lapply(1:length(unique(trajectory)), FUN=function(i) {
	lines(longitude[[1]], latitude[[i]])
	NULL
	}


Ott

-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._



More information about the R-help mailing list