I am trying to use the function fortify in R to plot the map. But I am always getting an error while processing the data. I read the shape file using the following code:
shape <- readShapeSpatial("Lond_City/lond_city.shp")
The shapefile can be found on the following dropbox location:
https://www.dropbox.com/sh/d4w6saailydtu1r/5oIa56xV6S
Then I tried to use the following command :
shape1 <- fortify(shape,region="data")
In the above code, what should I put in Place of “data”. This is the place which seems confusing. I can open the data or shapefile in R. However, when I run the fortify line I get the following error:
Error in ‘[.data.frame'(attr, , region) : undefined columns selected
Can anybody tell me how to properly fortify a shape file with example ? The reason I want to use fortify is that I want to combine the shape file with the data points.
Thank you so much.
Jdbaba
Your problem is that you need to give
fortifya column that actually exists. If you typestr(lon.shape)from my example code below, you will see that there is noregioncolumn:Instead, try using
name, like this:Which produces this data frame:
Here’s one way to go about it, start to finish:
…resulting in the following: