map
Draw Geographical Maps
Draw lines and polygons as specified by a map database.
- Keywords
- hplot
Usage
map(database, regions) # simple form
map(database = "world", regions = ".", exact = FALSE, boundary = TRUE,
interior = TRUE, projection = "", parameters = NULL, orientation = NULL,
fill = FALSE, color = 1, plot = TRUE, add = FALSE, namesonly = FALSE,
xlim = NULL, ylim = NULL, wrap = FALSE, resolution = 1, type = "l",
bg, mar, ...)
Arguments
- database
- character string naming a geographical database, or a list of
x
,y
, andnames
obtained from a previous call tomap
. The string choices include aworld<
- regions
- character vector that names the polygons to draw. Each database is composed of a collection of polygons, and each polygon has a unique name. When a region is composed of more than one polygon, the individual polygons have the name of the r
- exact
- If
TRUE
, only exact matches withregions
are selected for drawing. IfFALSE
, each element ofregions
is matched as a regular expression against the polygon names in the database and all m - boundary
- If
FALSE
, boundary segments are not drawn. A boundary segment is a line segment of the map that bounds only one of the polygons to be drawn. This argument is ignored iffill
isTRUE
. - interior
- If
FALSE
, interior segments are not drawn. An interior segment is a line segment of the map that bounds two of the polygons to be drawn. This argument is ignored iffill
isTRUE
. - projection
- character string that names a map projection to use.
See
mapproject
(in themapproj
library). The default is to use a rectangular projection with the aspect ratio chos - parameters
- numeric vector of parameters for use with the
projection
argument. This argument is optional only in the sense that certain projections do not require additional parameters. If a projection does require additional parameters, - orientation
- up to three numbers specifying the orientation of
non-standard projections.
Default is
c(90, 0, m)
, wherem
is the middle of the longitude range. - fill
- logical flag that says whether to draw lines or fill areas.
If
FALSE
, the lines bounding each region will be drawn (but only once, for interior lines). IfTRUE
, each region will be filled using colors from the - color
- vector of colors.
If
fill
isFALSE
, the first color is used for plotting all lines, and any other colors are ignored. Otherwise, the colors are matched one-one with the polygons that get selected by theregi
- plot
- logical flag that specifies whether plotting
should be done.
If
plot
isTRUE
the return value ofmap
will not be printed automatically . - add
- logical flag that specifies whether to add to the
current plot.
If
FALSE
, a new plot is begun, and a new coordinate system is set up. - namesonly
- If
TRUE
, the return value will be a character vector of the names of the selected polygons. See the Value section below. - xlim
- two element numeric vector giving a range of longitudes, expressed in degreees, to which drawing should be restricted. Longitude is measured in degrees east of Greenwich, so that, in particular, locations in the USA have negative longi
- ylim
- two element numeric vector giving a range of latitudes, expressed in degrees, to which drawing should be restricted. Latitude is measured in degrees north of the equator, so that, in particular, locations in the USA have positive
- wrap
- If TRUE, lines that cross too far across the map (due to a strange projection) are omitted.
- resolution
- number that specifies the resolution with which to draw the map. Resolution 0 is the full resolution of the database. Otherwise, just before polylines are plotted they are thinned: roughly speaking, successive points on the polyline that a
- type
- character string that controls drawing of the map.
Aside from the default
type = "l"
, the valuetype = "n"
can be used to set up the coordinate system and projection for a map that will be added-to in later calls. - bg
- background color
- mar
- margins, as in
par
. - ...
- Extra arguments passed to
polygon
orlines
.
Value
- If
plot = TRUE
, a plot is made where the polygons selected fromdatabase
, through theregions
,xlim
, andylim
arguments, are outlined (fill
isFALSE
) or filled (fill
isTRUE
) with the colors incolor
.The return value is a list with
x
,y
,range
, andnames
components. This object can be used as adatabase
for successive calls tomap
and functions. Iffill
isFALSE
, thex
andy
vectors are the coordinates of successive polylines, separated byNA
s. Iffill
isTRUE
, thex
andy
vectors have coordinates of successive polygons, again separated byNA
s. Thus the return value can be handed directly tolines
orpolygon
, as appropriate.When
namesonly
isTRUE
, only the names component is returned.After a call to
map
for which theprojection
argument was specified there will be a global variable.Last.projection
containing information about the projection used. This will be consulted in subsequent calls tomap
which useprojection = ''
.
synopsis
map(database = "world", regions = ".", exact = FALSE, boundary = TRUE, interior = TRUE, projection = "", parameters = NULL, orientation = NULL, fill = FALSE, color = 1, plot = TRUE, add = FALSE, namesonly = FALSE, xlim = NULL, ylim = NULL, wrap = FALSE, resolution = 1, type = "l", bg, mar, ...)
References
Richard A. Becker, and Allan R. Wilks,
"Maps in S",
AT&T Bell Laboratories Statistics Research Report [93.2], 1993.
Richard A. Becker, and Allan R. Wilks,
"Constructing a Geographical Database",
AT&T Bell Laboratories Statistics Research Report [95.2], 1995.
See Also
map.text
, map.axes
,
map.scale
, map.grid
(in the mapproj
library)
Examples
map() # low resolution map of the world
map('usa') # national boundaries
map('county', 'new jersey') # county map of New Jersey
map('state', region = c('new york', 'new jersey', 'penn')) # map of three states
map("state", ".*dakota") # map of the dakotas
if(require(mapproj))
map('state', proj = 'bonne', param = 45) # Bonne equal-area projection of states
# names of the San Juan islands in Washington state
map('county', 'washington,san', names = TRUE, plot = FALSE)
# national boundaries in one color, states in another
# (figure 5 in the reference)
map("state", interior = FALSE)
map("state", boundary = FALSE, lty = 2, add = TRUE)
# plot the ozone data on a base map
# (figure 4 in the reference)
data(ozone)
map("state", xlim = range(ozone$x), ylim = range(ozone$y))
text(ozone$x, ozone$y, ozone$median)
box()