[R-sig-Geo] merge, coordinates, sort order
Tom Gottfried
tom.gottfried at o2mail.de
Fri Aug 3 05:22:51 CEST 2012
Please try to provide a reproducible example. The object
'correspondence' you use in merge() is unknown (at least to me). Further
there are some syntax errors in your code that shouldn't have permitted
you running it.
regards,
Tom
Am 02.08.2012 22:13, schrieb Aksel Olsen:
> Hi,
>
> I am having trouble mapping and labeling with ggplot, including having
> the issue is that merge() didn't work as planned for me, seemingly
> joining by the row id or FID instead of the provided key. But here I am
> trying to extract coordinates from the spatial data frame and plot them
> with a data value from another table, relating based on the FID key.
>
> Here is the essence of what I have:
>
> *load shapefile*
> geography_sp1<- readShapeSpatial(qual_shp_file)
> row.names(as(geography_sp1, "data.frame))
>
> *change ids to primary key
> *geography_sp1<- spChFIDs(geography_sp1,
> as.character(geography_sp1#superdistr))
> *
> **Extracting coordinates--my problem here is that I am not sure that the
> columns in the data frame are properly aligned--can I get FIDS out or
> other identifier when calling the coordinates function?
> * coords<-data.frame(coordinates(geography_sp1),
> row.names(sapply(slot(geography_sp1, "polygons"), function(x) slot (x,
> "ID"))
>
> *Getting the actual order of records:
>
> *coords$sort_id<- as.integer(row.names(coords))
>
> *and then, to add attributes from the correspondence table
>
> *coords<- merge(x=coords, y=correspondence, by.x="sort_id",
> by.y="superdistr", all.x=T)
>
> As noted,
> Best,
> Aksel
>
>
> [[alternative HTML version deleted]]
>
> _______________________________________________
> R-sig-Geo mailing list
> R-sig-Geo at r-project.org
> https://stat.ethz.ch/mailman/listinfo/r-sig-geo
More information about the R-sig-Geo
mailing list