I would like to ask how to plot sf
object in leaflet from leaflet package
I am aware about mapview package
that can plot it however I prefer using lealfet package.
I provided example down below:
library(leaflet)
library(eurostat)
library(dplyr)
library(ggplot2)
options(readr.default_locale=readr::locale(tz="Europe/Berlin"))
df60 <- get_eurostat_geospatial(resolution = 60)
CE.sf <- df60 %>%
dplyr::filter(LEVL_CODE == 2 & CNTR_CODE %in% c("AT","CZ","DE","HU","PL","SK")) %>%
dplyr::select(NUTS_ID)
plot(CE.sf)
CE.sf %>%
ggplot() +
geom_sf(color = "black", size = 0.4)
CE = sf::as_Spatial(CE.sf)
leaflet() %>%
addProviderTiles("CartoDB.Positron") %>%
addPolygons(data= CE, color = "green")
I need to reproduce plot from line 15 in leaflet, I found some ideas here: https://gis.stackexchange.com/questions/239118/r-convert-sf-object-back-to-spatialpolygonsdataframe
However using this approach does not work.