[R] add city and point in the map

Ray Brownrigg Ray.Brownrigg at mcs.vuw.ac.nz
Thu Apr 27 23:30:14 CEST 2006

> From: YIHSU CHEN <yschen at jhu.edu>
> Date: Thu, 27 Apr 2006 10:50:49 -0400
> I'm trying to use packages "maps" and "mapdata" (see blow) to display
> the research resutls on map (Mid-Atlantic region).  In particular, I
> need to mark a number of points in the map by giving their latitude and
> longitude information.  For instance, I would like to mark a point on
> (long, lat) =(75.56027, 39.09271).  Also, I need to mark several cities
> that I suspect might not in the "world.cities" database such as
> Baltimore, etc.  Presumably, I can do the same thing by finding out the
> lat and long infor of Baltimroe and add text next to the point I mark.
> Thanks a billion
> Yihsu
> library(maps)
> library(mapdata)
> state.list <- c("maryland","new jersey","west virginia", "virginia","ohio","delaware","pennsylvania","kentucky","indiana","north carlina")
> map("state",state.list)
> map.cities(x=world.cities, Country="US",minpop=100000)
Several things:
1) the US is west of longitude 0, so you need longitude -75.56027
2) map.cities uses x=world.cities by default, so you don't need to
specify it in your call, but if you do specify it, you need to precede
it with a call to:
[I guess this is a bug, perhaps just at the documentation level]
3) map.cities takes country= as an argument, not Country=
4) The US is identified in the maps package as USA, so you would use
country="USA" (but you don't need country= anyway, beacause your map is
only of the USA, so there are no cities to exclude).
5) Baltimore is in world.cities, try map.cities(minpop=500000, label=T)
6) If you really want North Carolina, you need to spell it correctly

So what you need is:
# library(mapdata)	# not needed for this
state.list <- c("maryland", "new jersey", "west virginia", "virginia",
  "ohio", "delaware", "pennsylvania", "kentucky", "indiana", "north carolina")
map("state", state.list)

Hope this helps,
Ray Brownrigg

More information about the R-help mailing list