Search code examples
rleafletplot3d

leaflet map: remove road layer


I want to remove roads from my leaflet map in R. Is there a way to remove layers we want such as roads, lakes, state boundaries, etc.?

Sample code:

library(leaflet)
library(plot3D)
top = 45      # north lat
left = -110   # west long
right = -90   # east long
bottom =  32  # south lat

longitudes= seq(left,right, length.out = 3)
latitude=seq(bottom,top,length.out = 5)

 latlons_mesh=mesh(longitudes,latitude)

 longitude=as.vector(latlons_mesh$x)
 latitude=as.vector(latlons_mesh$y)

 mydata=data.frame(longitude=longitude,
                  latitude=latitude)

 leaflet(mydata)%>%fitBounds(right,bottom,left,top)%>%
    addTiles()%>%
    addMarkers()

enter image description here


Solution

  • The roads and other features are part of the base tile, or you can call it 'background'.

    By default the tiles are OSM's, but you can change with the addTProviderTiles() function, giving as argument one of the provider listed here.

    For example a provider withour roads or boundaries is Esri.WorldShadedRelief:

    leaflet(mydata) %>%
        fitBounds(right,bottom,left,top)%>%
        addProviderTiles('Esri.WorldShadedRelief') %>%
        addMarkers()