R语言ggplot叠加墨西哥城shp与Airbnb空间数据集显示异常求助
我在R语言中尝试将墨西哥城的shp地图与Kaggle上的墨西哥城Airbnb数据集进行叠加可视化。单独绘制两个数据集时显示正常,但叠加后出现异常效果。
单独绘制地图
cdmx3 <- st_read("inegi/09_CDMX/cartografia/municipal.shp") ggplot() + geom_sf(data = cdmx3, color = "black") + ggtitle("Municipios de CDMX")
单独绘制时显示正常,呈现墨西哥城16个行政区的多边形边界。
单独绘制Airbnb点位
airbnb_mexico <- read.csv(file = "listings.csv") airbnb_mexico_sf <- st_as_sf(x = airbnb_mexico, coords = c("longitude","latitude")) ggplot() + ggtitle("Municipios de CDMX") + geom_sf(data= airbnb_mexico_sf, color = "blue")
单独绘制时显示正常,呈现墨西哥城范围内的Airbnb点位分布。
叠加操作及异常结果
我尝试将两个sf数据集设置为相同CRS:
st_crs(airbnb_mexico_sf) <- st_crs(cdmx3)
但叠加后显示异常:
ggplot() + geom_sf(data = cdmx3, color = "black", fill = "cyan1") + ggtitle("Municipios de CDMX") + geom_sf(data= airbnb_mexico_sf, color = "blue")
叠加后地图与点位完全错位,无法匹配显示。
数据集摘要信息
cdmx3
Simple feature collection with 16 features and 261 fields
Geometry type: POLYGON
Dimension: XY
Bounding box: xmin: 2776218 ymin: 786788.9 xmax: 2820850 ymax: 846749.5
Projected CRS: Mexico_ITRF2008_LCC
First 10 features:...
airbnb_mexico_sf
Simple feature collection with 19852 features and 14 fields
Geometry type: POINT
Dimension: XY
Bounding box: xmin: -99.33963 ymin: 19.16914 xmax: -98.96297 ymax: 19.55734
Projected CRS: Mexico_ITRF2008_LCC
First 10 features:...
我已尝试将两个sf数据集设置为相同的CRS(Mexico_ITRF2008_LCC),但问题仍未解决,恳请各位提供反馈与建议。
内容的提问来源于stack exchange,提问作者Enrique

