Learn R Programming

TeachingDemos (version 1.2)

recenter.Map: Recenter a Map object from the maptools package.

Description

Most maps are centered at a longitude of 0 with points of east longitude plotted on the right side of the map and points with west longitude plotted to the left. This function transforms the points to have a new center moving polygons from the right to left or left to right.

Usage

recenter.Map(Map, center = 0, range = c(-180, 180))

Arguments

Map
A Map object from the maptools package.
center
The new longitude to use as the center.
range
The range of possible longitudes on the original scale.

Value

  • An object of class Map (from the maptools package) that is a copy of the input Map but with the longitudes shifted.

Details

Plotting a map of the United States can place some of the Alaskan islands to the far right of the map (they have east longitude). This function shifts the longitudes to bring the seperate pieces together. Polygons will only be shifted if all points can move together, it will not split a polygon between sides of the map.

See Also

plot.polylist

Examples

Run this code
## this assumes that the time zone shape files have been downloaded
## from: http://openmap.bbn.com/data/shape/timezone/
## and the US states map (st99_d00) files have been downloaded from
## http://www.census.gov/geo/www/maps/

us <- read.shape('st99_d00')
tz <- read.shape('WRLDTZA')
plot(Map2poly(us))
plot(Map2poly(recenter.Map(us,-100)))
plot(Map2poly(recenter.Map(tz,-165)))

Run the code above in your browser using DataLab