[英]Polygon Maps in R (spatial data)
有人可以根据房地产数据集( https://docs.google.com/spreadsheets/d/1g_awI6hnD80IVeZDOWpvU_NHdHxsk_Uyo8HML9p-yHo/edit#gid=0 )帮助我创建多边形地图吗? 我想获取一份萨克拉曼多的区域地图,用不同的颜色代表不同的房地产价格。
我在下面提供的代码来自示例多边形R代码。 我无法弄清楚“合并”功能在多边形地图中的工作方式。
谢谢,
#load libraries
library(ggmap)
library(ggplot2)
library(gpclib)
library(rgeos)
getClass("Polygon")
getClass("SpatialPolygons")
realestate.f <- fortify(realestate, region = "zip")
realestate.f <- merge(realestate.f, realestate, by.x = "longitude", by.y = "latitude")
head(realestate.f)
Map <- ggplot(realestate.f, aes(longitude, latitude, price)) +
geom_polygon() + coord_equal() +
labs(x = "longitude", y = "latitude", "price") +
ggtitle("Sacramento Real Estate Prices")
Map + scale_fill_gradient(low = "white", high = "black")`
@Yun Zhou:看来您是从点数据开始的。 我相信您首先需要将数据框转换为SpatialPointsDataFrame,然后才能将点转换为多边形数据(或某些密度函数)。
#dataframe from csv
df.in
# Coerce to SpatialPointsDataFrame
coordinates(df.in) = c("latitude", "longitude")
class(df.in) #it should be a sptial points data frame
plot(df.in)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.