wmap_sf: create an sf worldmap layer or gg

View source: R/wmap.r

wmap_sfR Documentation

create an sf worldmap layer or gg

Description

This function is intended to be used in two ways: first, to overlay a world map on an existing gg object, and second, to create a base world map using ggplot2.

Usage

wmap_sf(
  sfmap = NULL,
  sf_resol = 50,
  pacific_centered = TRUE,
  as_gg = TRUE,
  lgl = NULL,
  ltl = NULL,
  lgb = NULL,
  ltb = NULL,
  ...
)

Arguments

sfmap

World map data in sf format, Default: NULL

sf_resol

Resolution of sf world map data passed to rnaturalearth::ne_countries(scale), Default: 50 (medium).

pacific_centered

If TRUE (default), the world map is centred on the Pacific Ocean; if FALSE, the world map is centred on the prime meridian (i.e. the meridian on Greenwich).

as_gg

Whether or not to make a gg object, Default: TRUE

lgl

Longitude limits, Default: NULL

ltl

Latitude limits, Default: NULL

lgb

Longitude breaks, Default: NULL

ltb

Latitude breaks, Default: NULL

...

Arguments passed to geom_sf

Details

If sfmap is NULL, the default map projection system is a geographic coordinate system based on the WGS84. It has not yet been checked whether there are any problems with other coordinate reference systems. See example and vignette("wmap_sf").

Value

gg or a list (LayerInstance)

See Also

ne_countries st_break_antimeridian, st_shift_longitude

Examples

library(ggplot2)
library(frabento)
set.seed(180)

df <- data.frame(Long = seq(140, 240, by = 5),
                 Lati = runif(n = 21, min = 40, max = 65),
                 group = c(rep(1:5, each = 4), 6))

# plain world map as pacific centered (default)
wmap_sf()

# plain world map as Greenwich centered
wmap_sf(pacific_centered = FALSE)

# Trim worldmap and overlay data points on worldmap
wmap_sf(lgl = c(135, 245), ltl = c(35, 70)) +
  geom_point(data = df, aes(x = Long, y = Lati, color = as.factor(group)))

# Trim world map and overlay worldmap on data points
ggplot() +
  geom_point(data = df, aes(x = Long, y = Lati, color = as.factor(group))) +
  wmap_sf(as_gg = FALSE, lgl = c(135, 245), ltl = c(35, 70))

JK-junkin/frabento documentation built on Oct. 20, 2023, noon