有人可以帮我根据房地产数据集(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")`
答案 0 :(得分:0)
#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)