我想问一下怎么画图sf
传单中的对象来自leaflet package
我知道mapview package
可以绘制它,但我更喜欢使用 lealfet 包。
我在下面提供了示例:
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")
我需要重现传单中第 15 行的情节,我在这里找到了一些想法:https://gis.stackexchange.com/questions/239118/r-convert-sf-object-back-to-spatialpolygonsdataframe https://gis.stackexchange.com/questions/239118/r-convert-sf-object-back-to-spatialpolygonsdataframe
然而使用这种方法是行不通的。
您只是忘记设置data
论据中的leaflet()
功能。此外,您不需要转换sf
反对sp
format:
# packages
library(leaflet)
library(eurostat)
library(dplyr)
library(ggplot2)
options(readr.default_locale=readr::locale(tz="Europe/Berlin"))
df60 <- get_eurostat_geospatial(resolution = 60)
#> sf at resolution 1:60 read from local file
CE.sf <- df60 %>%
filter(LEVL_CODE == 2 & CNTR_CODE %in% c("AT","CZ","DE","HU","PL","SK")) %>%
select(NUTS_ID)
plot(CE.sf)
leaflet(CE.sf) %>%
addProviderTiles("CartoDB.Positron") %>%
addPolygons(color = "green")
Created on 2020-05-01 by the reprex package https://reprex.tidyverse.org (v0.3.0)
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)