【发布时间】:2020-04-27 21:30:09
【问题描述】:
我正在从一个 shapefile 中读取空间数据,该文件包含一个省内 100 个地区的位置。 在另一个数据框中,我有每个地区的人口数据。
我正在尝试使用 ggplot 创建省份地图(来自 shapefile)并根据人口规模为每个地区着色。这里的问题是我不知道如何填写 由 shapefile 获取的地图,其颜色基于另一个数据框中包含的地区对应的人口值。
请注意,我理解下面的代码不起作用,但它说明了我直观地试图完成的事情
districts_from_shapefile <- readOGR("districts.shp")
districts_with_pop <- read.csv(file = "districts_populations.csv")
ggplot() +
geom_polygon(data=districts_from_shapefile, aes(x=long,y=lat,group=group)) +
geom_polygon(data=districts_with_pop, aes(fill=districts_with_pop$population))
谢谢!
【问题讨论】:
-
那里有很多教程。比如this one呢?
-
如果你能提供
dput()格式的数据和shapefile我可以帮你。
标签: r ggplot2 data-science shapefile sf