The following code chunks demonstrate:

  1. The ease of using the mapView() function to quickly map spatial data.
  2. However, the basemaps are not very good for marine data.
  3. The leaflet() function has all the flexibility, including with changing the basemap to the best possible Esri Ocean Basemap with labels, but it requires more code to replicate the original mapView() map.

Note:

1 mapView()

Use North Carolina (NC) Sudden Infant Death Syndrome (SIDS) sample data. (For details: ?nc.)

Code
library(sf)
library(mapview)

# sample data 
nc <- sf::st_read(system.file("shape/nc.shp", package="sf"), quiet=TRUE) |>
  st_transform(4326)

mapview::mapView(nc, zcol="SID74")

2 leaflet()

Code
library(leaflet)

leaflet::leaflet() |>
  # add base: blue bathymetry and light brown/green topography
  addProviderTiles(
    "Esri.OceanBasemap",
    options = providerTileOptions(
      variant = "Ocean/World_Ocean_Base")) |>
  # add reference: placename labels and borders
  addProviderTiles(
    "Esri.OceanBasemap",
    options = providerTileOptions(
      variant = "Ocean/World_Ocean_Reference"))

3 ms_basemap()

This functionmsens::ms_basemap() is really just a wrapper function for the leaflet() example above.

Code
library(glue)
library(msens)  # remotes::install_github("MarineSensitivity/msens")

msens::ms_basemap() |> 
  addPolygons(
    data  = nc,
    label = ~NAME,
    popup = ~glue("NAME: {NAME}<br>FIPS: {FIPS}"))

4 ms_basemap() + popupTable()

Code
library(leafpop)

msens::ms_basemap() |> 
  leaflet::addPolygons(
    data  = nc,
    popup = leafpop::popupTable(nc))

5 ms_basemap() + popupTable() + addLegend()

leaflet::

mapview::

Code
# color palette
pal <- colorNumeric(
  palette = "viridis",
  domain  = nc$SID74)

msens::ms_basemap() |> 
  leaflet::addPolygons(
    data         = nc,
    popup        = leafpop::popupTable(nc),
    color        = "black",
    weight       = 1,
    fillColor    = ~pal(SID74),
    fillOpacity  = 0.6) |> 
  leaflet::addLegend(
    pal    = pal,
    values = nc$SID74,
    title  = "nc - SID74")