map.grid: Draw a latitude/longitude grid on a projected map

Description Usage Arguments Value See Also Examples

View source: R/mapproj.r

Description

Draws a grid on an existing map.

Usage

1
2
map.grid(lim, nx=9, ny=9, labels=TRUE, pretty=TRUE, cex, col, lty,
  font, ...)

Arguments

lim

a vector of 4 numbers specifying limits: c(lon.low, lon.high, lat.low, lat.high). lim can also be a list with a component named range, such as the result of map, from which limits are taken.

nx, ny

the desired number of equally-spaced longitude and latitude lines

labels

logical to indicate if grid lines should be labeled with longitude/latitude values.

pretty

If TRUE, grid lines will be placed at round numbers.

cex, col, lty, font

passed to arguments to par

...

additional arguments passed to lines and text, e.g. col to change the color of the grid and lty to change the line type.

Value

Equally-spaced lines of constant longitude and lines of constant latitude are superimposed on the current map, using the current projection. These lines will appear curved under most projections, and give an idea of how the projection works.

See Also

map

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
library(maps)
m <- map("usa", plot=FALSE)
map("usa", project="albers", par=c(39, 45))
map.grid(m)

# get unprojected world limits
m <- map('world', plot=FALSE)

# center on NYC
map('world', proj='azequalarea', orient=c(41, -74, 0))
map.grid(m, col=2)
points(mapproject(list(y=41, x=-74)), col=3, pch="x", cex=2)

map('world', proj='orth', orient=c(41, -74, 0))
map.grid(m, col=2, nx=6, ny=5, label=FALSE, lty=2)
points(mapproject(list(y=41, x=-74)), col=3, pch="x", cex=2)

# center on Auckland
map('world', proj='orth', orient=c(-36.92, 174.6, 0))
map.grid(m, col=2, label=FALSE, lty=2)
points(mapproject(list(y=-36.92, x=174.6)), col=3, pch="x", cex=2)

m <- map('nz')
# center on Auckland
map('nz', proj='azequalarea', orient=c(-36.92, 174.6, 0))
points(mapproject(list(y=-36.92, x=174.6)), col=3, pch="x", cex=2)
map.grid(m, col=2)

Example output

Loading required package: maps
Warning message:
In map("world", proj = "orth", orient = c(41, -74, 0)) :
  projection failed for some data
Warning message:
In map("world", proj = "orth", orient = c(-36.92, 174.6, 0)) :
  projection failed for some data

mapproj documentation built on Feb. 3, 2020, 5:06 p.m.

Related to map.grid in mapproj...