Search code examples
rmapsr-leaflet

Polygon background in leaflet


Is there a way (better in R not to download any additional datasets) how to make polygon (or more visible country borders) in leaflet

Using simple code

m = leaflet() %>%
addProviderTiles("CartoDB.Positron") %>%
addCircles(lat=15,lng=18, radius = 300, color = "blue")

m

Solution

  • There is a world sf-dataset in spData-package.

    library(leaflet)
    library(sf)
    library(spData)
    
    leaflet() %>% 
    addProviderTiles("CartoDB.Positron") %>% 
    addPolygons(data = world[world$continent == "Europe",], weight = 1)
    

    If you just want the outlines of the countries, use: addPolylines()

    enter image description here