Hello I am trying to draw a basic black and white map of two European countries. After searching some key words in google and reading many pages I arrived to the conclusion that persp() could be used to draw that map. I have prepared three small example files, which are supposed to be the files required for running that function. xvector is a vector with the longitudes yvector is a vector with the latitudes zmatrix is supposed to the height, but since I only need a flat map I just gave the value 1 to each of the entries of the matrix (I am not sure this is correct though). The first question for me when using persp() is that x and y values should be in increasing values (following the instructions), but I understand that the coordinates x and y are actually pairs of values (longitude/latitude pairs of values) and if I order them in ascending order both then the pairing is gone. I guess I am totally lost! Still even if I try to run persp() by ordering in ascending value x and y values (even if it does not make sense for me) I still get this message: <- persp(xvector,yvector,zmatrix,theta=-40,phi=30) Error in persp.default(xvector, yvector, zmatrix, theta = -40, phi = 30) : increasing 'x' and 'y' values expected Any help is wellcome. Is there any other better function to draw a flat map (2D), also example of the imput files is wellcome. Thanks in advance. Rosario
Hi Rosario,
you might have a look at the "maps" and "maptools" (for
reading
shape-files) packages.
#e.g.
library(maps)
map("world",c("sweden","germany"))
Cheers
Am 04.08.2011 02:58, schrieb Rosario Garcia Gil:> Hello
>
> I am trying to draw a basic black and white map of two European countries.
>
> After searching some key words in google and reading many pages I arrived
to the conclusion that persp() could be used to draw that map.
>
> I have prepared three small example files, which are supposed to be the
files required for running that function.
>
> xvector is a vector with the longitudes
> yvector is a vector with the latitudes
> zmatrix is supposed to the height, but since I only need a flat map I just
gave the value 1 to each of the entries of the matrix (I am not sure this is
correct though).
>
> The first question for me when using persp() is that x and y values should
be in increasing values (following the instructions), but I understand that the
coordinates x and y are actually pairs of values (longitude/latitude pairs of
values) and if I order them in ascending order both then the pairing is gone. I
guess I am totally lost!
>
> Still even if I try to run persp() by ordering in ascending value x and y
values (even if it does not make sense for me) I still get this message:
>
> <- persp(xvector,yvector,zmatrix,theta=-40,phi=30)
> Error in persp.default(xvector, yvector, zmatrix, theta = -40, phi = 30) :
> increasing 'x' and 'y' values expected
>
> Any help is wellcome. Is there any other better function to draw a flat map
(2D), also example of the imput files is wellcome. Thanks in advance.
> Rosario
>
>
>
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
--
Eik Vettorazzi
Department of Medical Biometry and Epidemiology
University Medical Center Hamburg-Eppendorf
Martinistr. 52
20246 Hamburg
T ++49/40/7410-58243
F ++49/40/7410-57790
Rosario,
I don't think persp() is the function you need.
You may find that the maps in R's historical world map would work for you.
In that case you can try something like this (an example mapping France
and Germany):
require(maps)
map("world", c("France", "Germany"), xlim=c(-6.61,
17.21), ylim=c(40.73,
57.92))
If that doesn't meet your needs, you can use your own longitudes and
latitudes to draw the country borders, for example:
require(maps)
long <- c(-1.15, 1.45, 2.49, -0.37, -0.11, -2.56, -2.87, -5.52, -3.81,
-3.81, -1.15)
lat <- c(50.50, 52.35, 54.12, 54.91, 53.17, 52.21, 54.06, 53.61, 50.71,
50.71, 50.50)
# use the map() function to set up the long/lat projection without drawing
anything
map("world", xlim=range(long), ylim=range(lat), type="n")
lines(long, lat)
Jean
`·.,, ><(((º> `·.,, ><(((º> `·.,, ><(((º>
Jean V. Adams
Statistician
U.S. Geological Survey
Great Lakes Science Center
223 East Steinfest Road
Antigo, WI 54409 USA
From:
Rosario Garcia Gil <M.Rosario.Garcia@slu.se>
To:
"r-help@r-project.org" <r-help@r-project.org>
Date:
08/04/2011 01:05 AM
Subject:
[R] persp()
Sent by:
r-help-bounces@r-project.org
Hello
I am trying to draw a basic black and white map of two European countries.
After searching some key words in google and reading many pages I arrived
to the conclusion that persp() could be used to draw that map.
I have prepared three small example files, which are supposed to be the
files required for running that function.
xvector is a vector with the longitudes
yvector is a vector with the latitudes
zmatrix is supposed to the height, but since I only need a flat map I just
gave the value 1 to each of the entries of the matrix (I am not sure this
is correct though).
The first question for me when using persp() is that x and y values should
be in increasing values (following the instructions), but I understand
that the coordinates x and y are actually pairs of values
(longitude/latitude pairs of values) and if I order them in ascending
order both then the pairing is gone. I guess I am totally lost!
Still even if I try to run persp() by ordering in ascending value x and y
values (even if it does not make sense for me) I still get this message:
<- persp(xvector,yvector,zmatrix,theta=-40,phi=30)
Error in persp.default(xvector, yvector, zmatrix, theta = -40, phi = 30) :
increasing 'x' and 'y' values expected
Any help is wellcome. Is there any other better function to draw a flat
map (2D), also example of the imput files is wellcome. Thanks in advance.
Rosario
______________________________________________
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide
http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
[[alternative HTML version deleted]]
Am Donnerstag, den 04.08.2011, 02:58 +0200 schrieb Rosario Garcia Gil:> I am trying to draw a basic black and white map of two European countries. >Are you planning just to draw the boundaries? Or what do you mean by "basic black and white".> After searching some key words in google and reading many pages I arrived to the conclusion that persp() could be used to draw that map.If you want to create a 3D map where z are, say, the altitudes, yes. Have you read http://cran.r-project.org/view=spatial ? There is no mentioning of persp().> I have prepared three small example files, which are supposed to be the files required for running that function. >I haven't seen these files as attachments of your mail. I am certain they would help us a lot to see what your problem is.> xvector is a vector with the longitudes > yvector is a vector with the latitudes > zmatrix is supposed to the height, but since I only need a flat map I just gave the value 1 to each of the entries of the matrix (I am not sure this is correct though). >Then persp() will draw you a mesh of a flat plane, which is not informative, which gives me the impression that persp() is not hat you need. Have you run example(persp) at all? The result does not even look "basic black and white".> The first question for me when using persp() is that x and y values should be in increasing values (following the instructions), but I understand that the coordinates x and y are actually pairs of values (longitude/latitude pairs of values) and if I order them in ascending order both then the pairing is gone. I guess I am totally lost! > > Still even if I try to run persp() by ordering in ascending value x and y values (even if it does not make sense for me) I still get this message: > > <- persp(xvector,yvector,zmatrix,theta=-40,phi=30) > Error in persp.default(xvector, yvector, zmatrix, theta = -40, phi = 30) : > increasing 'x' and 'y' values expected > > Any help is wellcome. Is there any other better function to draw a flat map (2D), also example of the imput files is wellcome. Thanks in advance. > Rosario > > ______________________________________________ > R-help at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code.