1

每个人!

我正在尝试创建丹佛都会区的等值线图,按人口普查区显示不同的住房价值。当我尝试映射时,它给了我'Error: Aesthetics must be either length 1 or the same as the data (83658): x, y, group, fill'... 如何解决这个问题,以便我可以创建可视化地图?

我阅读了各种问题,但似乎没有一个可以帮助回答这个问题。建议将不胜感激。下面是 20 个(共 588 个)数据点的样本。

谢谢!

1.加载包

library(maptools)
library(ggmap)
library(ggthemes)
library(rgdal)

2.选择、定义、绘制初始地图

 DenverMetro <- c(-105, 40, -104.8535, 39.3760)
    DenverMetroMap <- get_map(location=DenverMetro, 
                              source = "google", 
                              maptype = "roadmap",
                              zoom = 10,
                              crop=FALSE)
    ggmap(DenverMetroMap)

3.从shp文件导入多边形

DenverMetroCensusTracts <-readOGR(dsn = "c://Users/John/Denver_Housing_Project/ACS_Data/Final_Data", layer = "cb_2013_08_tract_500k")
proj4string(DenverMetroCensusTracts)
DenverMetroCensusTracts <-spTransform(DenverMetroCensusTracts,
                              CRS("+proj=longlat + datum=WGS84"))

4.创建初始人口普查区地图

ggmap(DenverMetroMap) + geom_polygon(aes(x = long, y = lat, group=id),
             data = DenverMetroCensusTracts, 
             color="white", 
             fill="orange",
             alpha = .4, size = .2)

5a. 导入丹佛房屋数据,将一个变量数值化,并与人口普查 shapefile 合并

        setwd('C:/Users/John/Denver_Housing_Project/ACS_Data/Final_Data')
        Median_Values_ACS_13_DHP <-read.csv('ACS_13_5YR_B25077_DHP.csv',
         na.strings=c("NA", "-", "?", "(X)"), header=TRUE)
        names(Median_Values_ACS_13_DHP) <-c("AFFGEOID", "Id2", "Geography", "Year",
                                             "HouseValue_Median", "HouseValue_Median_MOE_DHP")

 HouseValue_Median=as.numeric(as.character(Median_Values_ACS_13_DHP$HouseValue_Median))

Mapping  <-merge(DenverMetroCensusTracts, Median_Values_ACS_13_DHP, by.x="AFFGEOID") 

6.创建等值线图

ggmap(DenverMetroMap) + geom_polygon(aes(x = long, y = lat, group = id, 
 fill = HouseValue_Median), data = Mapping, alpha = .4, size = .2) +
 scale_fill_gradient()

GEO.id GEO.id2 GEO.display-label YEAR HD01_VD01 HD02_VD01 1400000US08001007801 8001007801 Census Tract 78.01, Adams County, Colorado 2013 150300 40311 1400000US08001007802 8001007802 Census Tract 78.02, Adams County, Colorado 2013 114700 4570 1400000US08001007900 8001007900 Census Tract 79, Adams County, Colorado 2013 118600 8228 1400000US08001008000 8001008000 Census Tract 80, Adams County, Colorado 2013 139000 10440 1400000US08001008100 8001008100 Census Tract 81, Adams County, Colorado 2013 29800 105549 1400000US08001008200 8001008200 Census Tract 82, Adams County, Colorado 2013 145100 6189 1400000US08001008308 8001008308 Census Tract 83.08, Adams County , 科罗拉多州 2013 46300 67342 1400000US08001988700 8001988700 人口普查区 9887, 亚当斯县,Colorado 2013 - ** 1400000US08001008309 8001008309 Census Tract 83.09, Adams County, Colorado 2013 36600 18824 1400000US08001008353 8001008353 Census Tract 83.53, Adams County, Colorado 2013 134600 8921 1400000US08001008401 8001008401 Census Tract 84.01, Adams County, Colorado 2013 241300 43038 1400000US08001008402 8001008402 Census Tract 84.02, Adams County, Colorado 2013 215900 15189 1400000US08001008505 8001008505 Census Tract 85.05, Adams County, Colorado 2013 174100 6525 1400000US08001008506 8001008506 Census Tract 85.06, Adams County, Colorado 2013 157300 15556 1400000US08001008507 8001008507 Census Tract 85.07, Adams County, Colorado 2013 177800 5644 1400000US08001008508 8001008508 Census Tract 85.08,亚当斯县,Colorado 2013 188700 10424 1400000US08001008523 8001008523 Census Tract 85.23, Adams County, Colorado 2013 268500 29657 1400000US08001008524 8001008524 Census Tract 85.24, Adams County, Colorado 2013 231200 4994 1400000US08001008526 8001008526 Census Tract 85.26, Adams County, Colorado 2013 284900 14945

4

0 回答 0