|
Hi there! I'm following an awesome guide to working with spatial data (http://www.frankdavenport.com/blog/2012/6/19/notes-from-a-recent-spatial-r-class-i-gave.html) and am running into an error that I can't figure out how to fix.
Disclaimer: I am very much an R n00b Here is the r script I am running: https://dl.dropbox.com/u/28231177/This%20Should%20Work.R data: https://dl.dropbox.com/u/28231177/my_data.csv shapefile: https://dl.dropbox.com/u/28231177/sfzipcodes.zip I am getting two errors: > 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 Anybody have any idea what is happening here or how to resolve this? Thanks!!!! |
|
On 08/05/2012 05:09 AM, mjkatsaros wrote:
> Hi there! I'm following an awesome guide to working with spatial data > (http://www.frankdavenport.com/blog/2012/6/19/notes-from-a-recent-spatial-r-class-i-gave.html) > and am running into an error that I can't figure out how to fix. > > Disclaimer: I am very much an R n00b > > Here is the r script I am running: > https://dl.dropbox.com/u/28231177/This%20Should%20Work.R > > data: https://dl.dropbox.com/u/28231177/my_data.csv > > shapefile: https://dl.dropbox.com/u/28231177/sfzipcodes.zip > > I am getting two errors: > >> 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* > > Anybody have any idea what is happening here or how to resolve this? Hi mjkatsaros, The data file doesn't have a column labelled "OBJECTID". I would try renaming the "zip" column to "OBJECTID". Jim ______________________________________________ [hidden email] mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. |
| Powered by Nabble | Edit this page |
