Skip to content
Prev 15906 / 29559 Next

fortify.SpatialPolygonsDataFrame error

Hey Christian,
As your example is not reproducible (i.e. no access to NUTS1 shapefile) its a bit hard to say exactly, but perhaps this might work for you:

# Try row.names() rather than rownames()
NUTS1 at data$id <- row.names(NUTS1 at data)   
NUTS1.points <- fortify(NUTS1, region="id")
NUT1.df <- dataframe(NUTS1)

# This join operation allows you to join attribute data from the shapefile (which I assume you have as NUTS1 is a SpatialPolygonsDataFrame) to each row of the data frame used for plotting
NUTS1.map <- join(NUTS1.points, NUTS1.df , by = "id" ) 

# To ggplot2 a geom_polygon is simply a filled geom_path - if you want transparent polygons you may as well use geom_path instead
p <- ggplot() + geom_path( data=NUTS1.map , aes( long , lat , group = group ) , colour="black" ) + coord_map()
print(p)

HTH,

Simon