Dear helpeRs,
I'm working with the map-package and came upon a problem which I
couldn't solve. I hope onee of you can. If not, this can be seen as a
suggestion for new versions of the package.
I'm trying to create a map of some European countries, filled with
colors corresponding to some values. Let's say I have the following
countries and I assign the following colors (fictional):
country2001 <- c("Austria", "Belgium",
"Switzerland",
"Czechoslovakia", "Germany", "Denmark",
"Spain", "Finland", "France",
"UK", "Greece", "Hungary", "Ireland",
"Israel", "Italy",
"Luxembourg", "Netherlands", "Norway",
"Poland", "Portugal",
"Sweden", "Slovenia")
color2001 <- c("green",
"yellow","red","red", "red",
"red", "red",
"red", "green", "red", "red",
"red", "red", "red", "red",
"red",
"red", "blue", "red", "red",
"red", "orange")
I then let the colors and the values correspond using 'match.map',
like this:
match <- match.map("world",country2001)
color <- color2001[match]
And finally I plot the map. It works perfectly fine.
map(database="world", fill=TRUE, col=color)
But as I mentioned, I want to create a map of Europe. So, I use xlim
and ylim to let some parts of the world fall of the map. The syntax
becomes like this:
map(database="world", fill=TRUE, col=color, xlim=c(-25,70),ylim=c
(35,71))
Now, a problem arises. The regions on the map are colored by the
vector 'color'. It needs therefore to correspond to the order in
which the polygons are drawn. Since some of the full world-map isn't
drawn this time, the color-vector doesn't correspond anymore. This
results in the coloring of the wrong countries.
Does anybody know of a way to solve this?
Thanks very much in advance,
Rense Nieuwenhuis
[[alternative HTML version deleted]]
On Tue, 26 Sep 2006, Rense Nieuwenhuis wrote:> Dear helpeRs, > > I'm working with the map-package and came upon a problem which I > couldn't solve. I hope onee of you can. If not, this can be seen as a > suggestion for new versions of the package. > > I'm trying to create a map of some European countries, filled with > colors corresponding to some values. Let's say I have the following > countries and I assign the following colors (fictional): > > country2001 <- c("Austria", "Belgium", "Switzerland", > "Czechoslovakia", "Germany", "Denmark", "Spain", "Finland", "France", > "UK", "Greece", "Hungary", "Ireland", "Israel", "Italy", > "Luxembourg", "Netherlands", "Norway", "Poland", "Portugal", > "Sweden", "Slovenia") > color2001 <- c("green", "yellow","red","red", "red", "red", "red", > "red", "green", "red", "red", "red", "red", "red", "red", "red", > "red", "blue", "red", "red", "red", "orange") > > I then let the colors and the values correspond using 'match.map', > like this: > > match <- match.map("world",country2001) > color <- color2001[match] > > And finally I plot the map. It works perfectly fine. > > map(database="world", fill=TRUE, col=color) > > > But as I mentioned, I want to create a map of Europe. So, I use xlim > and ylim to let some parts of the world fall of the map. The syntax > becomes like this: > > map(database="world", fill=TRUE, col=color, xlim=c(-25,70),ylim=c > (35,71)) > > Now, a problem arises. The regions on the map are colored by the > vector 'color'. It needs therefore to correspond to the order in > which the polygons are drawn. Since some of the full world-map isn't > drawn this time, the color-vector doesn't correspond anymore. This > results in the coloring of the wrong countries. > > Does anybody know of a way to solve this?Within the maps package: europe <- map(database="world", fill=TRUE, plot=FALSE, xlim=c(-25,70),ylim=c(35,71)) match <- match.map(europe,country2001) color <- color2001[match] map(database="world", fill=TRUE, col=color, xlim=c(-25,70),ylim=c(35,71)) but I'm afraid the "world" database precedes the dissolution of the Soviet Union, Czechoslovakia, and Yugoslavia, and doesn't code Sicily or Sardinia in Italy, so the result is perhaps not yet what you need: europe$names[grep("Sicily", europe$names)] <- "Italy:Sicily" europe$names[grep("Sardinia", europe$names)] <- "Italy:Sardinia" match <- match.map(europe,country2001) color <- color2001[match] map(database="world", fill=TRUE, col=color, xlim=c(-25,70),ylim=c(35,71)) deals with Italy, but you won't get Slovenia. There was a discussion about this on the R-sig-geo list in March this year starting here: http://finzi.psych.upenn.edu/R/Rhelp02a/archive/78303.html or equivalently: http://article.gmane.org/gmane.comp.lang.r.geo/299> > Thanks very much in advance, > > Rense Nieuwenhuis > [[alternative HTML version deleted]] > > ______________________________________________ > R-help at stat.math.ethz.ch 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. >-- 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 e-mail: Roger.Bivand at nhh.no
You may also want to look at the maptools (and sp) package, it can read
in and plot shapefiles from external sources.
Some sources of maps that maptools can plot include:
http://www.vdstech.com/map_data.htm
http://openmap.bbn.com/data/shape/timezone/
http://arcdata.esri.com/data_downloader/DataDownloader?part=10200&stackback
Hope this helps,
--
Gregory (Greg) L. Snow Ph.D.
Statistical Data Center
Intermountain Healthcare
greg.snow at intermountainmail.org
(801) 408-8111
-----Original Message-----
From: r-help-bounces at stat.math.ethz.ch
[mailto:r-help-bounces at stat.math.ethz.ch] On Behalf Of Rense Nieuwenhuis
Sent: Tuesday, September 26, 2006 2:21 AM
To: r-help at stat.math.ethz.ch
Subject: [R] Statistical data and Map-package
Dear helpeRs,
I'm working with the map-package and came upon a problem which I
couldn't solve. I hope onee of you can. If not, this can be seen as a
suggestion for new versions of the package.
I'm trying to create a map of some European countries, filled with
colors corresponding to some values. Let's say I have the following
countries and I assign the following colors (fictional):
country2001 <- c("Austria", "Belgium",
"Switzerland", "Czechoslovakia",
"Germany", "Denmark", "Spain",
"Finland", "France", "UK", "Greece",
"Hungary", "Ireland", "Israel", "Italy",
"Luxembourg", "Netherlands",
"Norway", "Poland", "Portugal",
"Sweden", "Slovenia")
color2001 <- c("green",
"yellow","red","red", "red",
"red", "red",
"red", "green", "red", "red",
"red", "red", "red", "red",
"red", "red",
"blue", "red", "red", "red",
"orange")
I then let the colors and the values correspond using 'match.map', like
this:
match <- match.map("world",country2001)
color <- color2001[match]
And finally I plot the map. It works perfectly fine.
map(database="world", fill=TRUE, col=color)
But as I mentioned, I want to create a map of Europe. So, I use xlim and
ylim to let some parts of the world fall of the map. The syntax becomes
like this:
map(database="world", fill=TRUE, col=color, xlim=c(-25,70),ylim=c
(35,71))
Now, a problem arises. The regions on the map are colored by the vector
'color'. It needs therefore to correspond to the order in which the
polygons are drawn. Since some of the full world-map isn't drawn this
time, the color-vector doesn't correspond anymore. This results in the
coloring of the wrong countries.
Does anybody know of a way to solve this?
Thanks very much in advance,
Rense Nieuwenhuis
[[alternative HTML version deleted]]
______________________________________________
R-help at stat.math.ethz.ch 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.