rleaflettmap

How to crop a small area from leaflet or tmap


Could someone show me how to crop this lake from a leaflet or tmap? Code and screenshot below:

library(sf)
library(tmap)
library(tmaptools)
library(leaflet)
 
test <- tm_basemap(c("Esri.DeLorme")) + 
tm_shape(onepoint) + tm_markers() + tm_view(set.view = c(lon = -120.02, lat = 39.100,zoom=11)) 
test

#Or with leaflet
leaflet() %>%
addProviderTiles("Esri.Delorme") %>%
  setView(lng = -120.02, lat = 39.100, zoom = 11)
  
  leaflet() %>% 
addTiles() %>%  
  setView(lng = -120.02, lat = 39.100, zoom = 11)

I would like Lake Tahoe to be cropped from the big map if possible. Thanks in advance

enter image description here


Solution

  • With tmap it's possible when using OSM tiles as basemap:

    library(tidyverse)
    library(tmap)
    library(tmaptools)
     
    # define bounding box around Lake Tahoe and get OSM data
    ext <- 0.2
    bbox_tahoe <- bb(c(-120.02 - ext, 39.1 - ext, -120.02 + ext, 39.1 + ext))
    osm <- read_osm(bbox_tahoe) 
    
    # plot OSM tiles as basemap
    tm_shape(osm) + 
      tm_rgb()
    

    Created on 2023-08-11 with reprex v2.0.2