【发布时间】:2017-07-03 09:56:51
【问题描述】:
我正在尝试在地图上绘制一些疾病事件数据的位置。
我用这个来导入数据:
ByTown<-readOGR(dsn="C:/temp/lyme/Towns", layer="Towns", encoding = "UTF-8", verbose= FALSE)
查看班级:
class(ByTown)
#getting this result
[1] "SpatialPolygonsDataFrame"
attr(,"package")
[1] "sp"
然后我将所有因素转换为字符数据,并再次使用class 检查是否还有SpatialPolygonsDataFrame,我这样做了:
然后我将我希望合并的数据格式化为与原始相同的标题:
townCount$City<-str_to_title(townCount$City)
然后我将计数数据geo_join到空间多边形数据框:
ByTown<-geo_join(ByTown, townCount,"MCD_NAME", "City")
然后我设置调色板并运行映射:
pal = colorQuantile("PuOr",ByTown$count, n=5 )
map<-leaflet(ByTown) %>%
addProviderTiles("CartoDB.Positron")%>%
addPolygons(fillColor = ~pal(count),
color = "#000000",
stroke = TRUE,
weight = 1,
smoothFactor = 0.5,
options(viewer = NULL))
map
我得到这个错误:
Error in derivePolygons(data, lng, lat, missing(lng), missing(lat), "addPolygons") :
addPolygons must be called with both lng and lat, or with neither.
我查看了坐标槽,其中有数据...我对错误感到困惑,并没有在网上找到任何有用的答案。这是坐标槽中第一个多边形的头部:
head(nByTown@polygons[[1]]@Polygons[[1]]@coords )
[,1] [,2]
[1,] 1036519 916318.7
[2,] 1036039 916355.8
[3,] 1031757 916299.7
[4,] 1027474 916244.5
[5,] 1026709 916198.1
[6,] 1026826 916248.3
每个人都有这个问题,找出根本原因并解决它?
【问题讨论】: