snapbox icon indicating copy to clipboard operation
snapbox copied to clipboard

should layer_mapbox forward ... to layer_spatial ?

Open MilesMcBain opened this issue 5 years ago • 2 comments

Could this for example be used to set layer opacity?

MilesMcBain avatar Dec 15 '20 05:12 MilesMcBain

A vector basemap with no background is already transparent. Edit: forwarding ... to layer_spatial() seems fine to me.

library(sf)
#> Linking to GEOS 3.8.0, GDAL 3.0.4, PROJ 6.3.1
library(ggplot2)
library(snapbox)

area <- st_bbox(
  c(xmin = 147, ymin = -43, xmax = 147.7, ymax = -42.65),
  crs = 4326
)

ggplot() +
  layer_mapbox(
    area, 
    map_style = mapbox_satellite(), 
    scale_ratio = 0.5
  ) +
  layer_mapbox(
    area, 
    map_style = "mapbox://styles/anthony-north/ckipret4b09ap18ofyrw4yea7", 
    scale_ratio = 0.5
  )
#> Warning in showSRID(uprojargs, format = "PROJ", multiline = "NO", prefer_proj
#> = prefer_proj): Discarded ellps WGS 84 in CRS definition: +proj=merc +a=6378137
#> +b=6378137 +lat_ts=0 +lon_0=0 +x_0=0 +y_0=0 +k=1 +units=m +nadgrids=@null
#> +wktext +no_defs +type=crs
#> Warning in showSRID(uprojargs, format = "PROJ", multiline = "NO", prefer_proj =
#> prefer_proj): Discarded datum World Geodetic System 1984 in CRS definition
#> Warning in showSRID(uprojargs, format = "PROJ", multiline = "NO", prefer_proj
#> = prefer_proj): Discarded ellps WGS 84 in CRS definition: +proj=merc +a=6378137
#> +b=6378137 +lat_ts=0 +lon_0=0 +x_0=0 +y_0=0 +k=1 +units=m +nadgrids=@null
#> +wktext +no_defs +type=crs
#> Warning in showSRID(uprojargs, format = "PROJ", multiline = "NO", prefer_proj =
#> prefer_proj): Discarded datum World Geodetic System 1984 in CRS definition
#> Warning in showSRID(uprojargs, format = "PROJ", multiline = "NO", prefer_proj
#> = prefer_proj): Discarded ellps WGS 84 in CRS definition: +proj=merc +a=6378137
#> +b=6378137 +lat_ts=0 +lon_0=0 +x_0=0 +y_0=0 +k=1 +units=m +nadgrids=@null
#> +wktext +no_defs +type=crs
#> Warning in showSRID(uprojargs, format = "PROJ", multiline = "NO", prefer_proj =
#> prefer_proj): Discarded datum World Geodetic System 1984 in CRS definition
#> Warning in showSRID(uprojargs, format = "PROJ", multiline = "NO", prefer_proj
#> = prefer_proj): Discarded ellps WGS 84 in CRS definition: +proj=merc +a=6378137
#> +b=6378137 +lat_ts=0 +lon_0=0 +x_0=0 +y_0=0 +k=1 +units=m +nadgrids=@null
#> +wktext +no_defs +type=crs
#> Warning in showSRID(uprojargs, format = "PROJ", multiline = "NO", prefer_proj =
#> prefer_proj): Discarded datum World Geodetic System 1984 in CRS definition

Created on 2020-12-15 by the reprex package (v0.3.0)

anthonynorth avatar Dec 15 '20 09:12 anthonynorth

Yup, can confirm this works well with other raster layers:

library(ggplot)
#> Error in library(ggplot): there is no package called 'ggplot'
library(sf)
#> Linking to GEOS 3.8.0, GDAL 3.0.4, PROJ 6.3.1
library(ggspatial)
library(snapbox)
library(raster)
#> Warning: package 'raster' was built under R version 4.0.3
#> Loading required package: sp

worldclim <- raster::getData('worldclim', var='prec', res=2.5, lon = 142.61, lat = -23.64)

area <- st_bbox(
  c(xmin = 101.03, ymin = -44.82, xmax = 168.23, ymax = -9.09),
  crs = 4326
)

rast <- raster::crop(worldclim[[1]], extent(area))
ggplot() +
  layer_spatial(rast) +
  layer_mapbox(area,
               map_style = "mapbox://styles/noamross/ckipi0rfl3ybv17p9dnom27ir/draft",
               scale_ratio = 1)
#> Warning in showSRID(uprojargs, format = "PROJ", multiline = "NO", prefer_proj
#> = prefer_proj): Discarded ellps WGS 84 in CRS definition: +proj=merc +a=6378137
#> +b=6378137 +lat_ts=0 +lon_0=0 +x_0=0 +y_0=0 +k=1 +units=m +nadgrids=@null
#> +wktext +no_defs +type=crs
#> Warning in showSRID(uprojargs, format = "PROJ", multiline = "NO", prefer_proj =
#> prefer_proj): Discarded datum World Geodetic System 1984 in CRS definition

Created on 2020-12-15 by the reprex package (v0.3.0)

noamross avatar Dec 15 '20 14:12 noamross