【发布时间】:2012-08-04 19:54:59
【问题描述】:
在尝试处理我似乎无法调试的数据时,我遇到了几个错误。
这是 R 脚本https://dl.dropbox.com/u/28231177/This%20Should%20Work.R
这是数据https://dl.dropbox.com/u/28231177/my_data.csv
这是我运行它们时包含错误的最后几行:
pds <- fortify(sf_map)
# Using OBJECTID to define regions.
pds$OBJECTID <- as.integer(pds$OBJECTID)
# Error in `$<-.data.frame`(`*tmp*`, "OBJECTID", value = integer(0)) :
# replacement has 0 rows, data has 16249
### Make the map
p1 <- ggplot(my_data, aes(map_id = zip))
p1 <- p1 + geom_map(aes(fill=vol, map_id = zip), map = pds)
p1 <- p1 + expand_limits(x = pds$lon, y = pds$lat) + coord_equal()
p1 + xlab("Basic Map with Default Elements")
# Error in unit(x, default.units) : 'x' and 'units' must have length > 0
【问题讨论】:
-
另外,这里是 shapefile dl.dropbox.com/u/28231177/sfzipcodes.zip
-
什么是名称(pds)?我敢说 OBJECTID 不是其中之一。 pds$OBJECTID
-
@mdsumner,这就是我得到的:
pds <- fortify(sf_map) # Using OBJECTID to define regions. names(pds) #[1] "long" "lat" "order" "hole" "piece" "group" "id"看起来你是对的。那应该设置到哪一列?身份证? -
我将 OBJECTID 更改为 id 并且没有看到第一个错误 (
"Error in $<-.data.frame...)。我仍然收到第二个空白图错误:( -
试试不长,调试很无聊,但要注意,不会花很长时间
标签: r csv import-from-csv