我正在尝试在弗吉尼亚州的部分地区创建一个邮政编码的等值线,以显示一些公司数据。除了最后一行,我可以让所有东西都正常运行aes(fill = growth)
。在那里,我收到一个错误:
错误:美学长度必须为 1,或与 dataProblems:growth 长度相同
这是我的数据:
- 弗吉尼亚北部邮政编码的 Shapefile
- 我感兴趣的邮政编码的 csv和相应的公司数据值。
我的代码:
library(ggplot2)
library(maptools)
library(rgdal)
library(plyr)
#set working directory
setwd("F:/Dropbox/Zip Codes")
#load Shapefile NOVA
Zips <- readOGR(dsn="F:/Dropbox/Zip Codes", layer="NOVA")
#load Company Data of Zip Codes
Company <- read.csv("Data.csv")
#set to data.frame
Company_df <- data.frame(Company)
#create growth vector
growth = Company_df[,'Growth']
#merge growth vector into Zips
Zips$growth = growth
#ggplot
Nmap = ggplot(Zips) +
aes(x = long, y = lat, group=group) +
geom_polygon() +
aes(fill = growth)
Nmap