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]]