
Last chance! 50% off unlimited learning
Sale ends in
coord_map
but uses the PROJ.4 library/package for projection
transformationcoord_proj
does, using the proj4::project()
function from
the proj4
package.
coord_proj(proj = NULL, inverse = FALSE, degrees = TRUE, ellps.default = "sphere", xlim = NULL, ylim = NULL)
NULL
will default to
a Robinson projectionTRUE
inverse projection is performed (from a
cartographic projection into lat/long), otherwise projects from
lat/long into a cartographic projection.TRUE
then the lat/long data is assumed to be in
degrees, otherwise in radiansNA
if no
datum should be added to proj (e.g. if you specify an ellipsoid
directly).A sample of the output from coord_proj() using the Winkel-Tripel projection:
coord_proj_01.pngoptions: width="100%" alt="Figure: coord_proj_01.png"
library(maps)
# World in Winkel-Tripel
world <- map_data("world")
world <- world[world$region != "Antarctica",]
gg <- ggplot()
gg <- gg + geom_map(data=world, map=world,
aes(x=long, y=lat, map_id=region))
gg <- gg + coord_proj("+proj=wintri")
gg
# U.S.A. Albers-style
usa <- world[world$region == "USA",]
usa <- usa[!(usa$subregion %in% c("Alaska", "Hawaii")),]
gg <- ggplot()
gg <- gg + geom_map(data=usa, map=usa,
aes(x=long, y=lat, map_id=region))
gg <- gg + coord_proj(
paste0("+proj=aea +lat_1=29.5 +lat_2=45.5 +lat_0=37.5 +lon_0=-96",
" +x_0=0 +y_0=0 +ellps=GRS80 +datum=NAD83 +units=m +no_defs"))
gg
# Showcase Greenland (properly)
greenland <- world[world$region == "Greenland",]
gg <- ggplot()
gg <- gg + geom_map(data=greenland, map=greenland,
aes(x=long, y=lat, map_id=region))
gg <- gg + coord_proj(
paste0("+proj=stere +lat_0=90 +lat_ts=70 +lon_0=-45 +k=1 +x_0=0",
" +y_0=0 +ellps=WGS84 +datum=WGS84 +units=m +no_defs"))
gg
Run the code above in your browser using DataLab