[R] help to make a map on R

Ronaldo Reis Jr. chrysopa at insecta.ufv.br
Wed Oct 2 21:26:50 CEST 2002


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

The first problem is to get the data.

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
T		-22.077349	-48.322140
T		-22.047001	-48.347443
T		-22.054266	-48.369331
T		-22.042810	-48.392612
T		-22.064812	-48.422195
T		-22.062544	-48.443497

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
T2		-22.072460	-48.044472
T3		-22.062767	-48.298473
T3		-22.077349	-48.322140
T3		-22.047001	-48.347443
T3		-22.054266	-48.369331
T3		-22.042810	-48.392612
T3		-22.064812	-48.422195
T3		-22.062544	-48.443497

Each trajectory is a line that is a little piece of my map.

After this, to make a map I execute:

tapply() for separate the coordinates for each trajectory, something like 
this:

> longitude <- tapply(longitude,trajectory,c)
> longitude
$T1
[1] -51.2871 -51.2659 -51.2072

$T2
[1] -48.0897 -48.0746 -48.0445

$T3
[1] -48.2985 -48.3221 -48.3474 -48.3693 -48.3926 -48.4222 -48.4435

> latitude <- tapply(latitude,trajectory,c)
> latitude
$T1
[1] -22.0456 -22.0671 -22.0670

$T2
[1] -22.0597 -22.0755 -22.0725

$T3
[1] -22.0628 -22.0773 -22.0470 -22.0543 -22.0428 -22.0648 -22.0625

The nest step is to make a plot with the coordinates.

> plot(longitude,latitude, asp = 1, type = "n")

And finally plot the lines for each trajectory, and all lines together, 
make a Sao Paulo's map and your cities limits.

> lines(longitude$T1,latitude$T1)
> lines(longitude$T2,latitude$T2)
> lines(longitude$T3,latitude$T3)

How can I make to automatized this process? Because I can about 3000 
trajectory.

Any other idea for make this is welcome.


Thanks for all

Inte mais
Ronaldo
-- 
And Bruce is effectively building BruceIX
	-- Alan Cox
--
|   //|\\   [*****************************][*******************]
|| ( õ õ )  [Ronaldo Reis Júnior          ][PentiumIII-600     ]
|     V     [ESALQ/USP-Entomologia, CP-09 ][HD: 30 + 10 Gb     ]
||  / l \   [13418-900 Piracicaba - SP    ][RAM: 128 Mb        ]
|  /(lin)\  [Fone: 19-429-4199 r.229      ][Video: SiS620-8Mb  ]
||/(linux)\ [chrysopa at insecta.ufv.br      ][Modem: Pctel-onboar]
|/ (linux) \[ICQ#: 5692561                ][SO: CL 7.0 (2.2.19)]
||  ( x )   [*****************************][*******************]
||| _/ \_Powered by Conectiva Linux 7.0 D+:) | Lxuser#: 205366

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