This is a bit of a workaround, but if you duplicate the UF column as the identifier column, as shown in the wiki example from my comments when preparing the data, the default values โโfor fortify will use the first column in the spatial data frame to separate accordingly, adding names under the id column .
library(maptools) library(ggplot2) library(sp) library(rgdal) library(rgeos) brMap <- readShapePoly("Google/BRASIL", IDvar = "UF", proj4string = CRS("+init=epsg:4236"), repair = TRUE, verbose = TRUE) brMap@data $id <- brMap@data $UF brMapDF <- fortify(brMap)
The resulting structure for brMapDF:
'data.frame': 9316 obs. of 7 variables: $ long : num -68.6 -68.7 -68.8 -68.8 -68.9 ... $ lat : num -11.1 -11.2 -11.2 -11.1 -11.1 ... $ order: int 1 2 3 4 5 6 7 8 9 10 ... $ hole : logi FALSE FALSE FALSE FALSE FALSE FALSE ... $ piece: Factor w/ 37 levels "1","2","3","4",..: 1 1 1 1 1 1 1 1 1 1 ... $ group: Factor w/ 81 levels "AC.1","AL.1",..: 1 1 1 1 1 1 1 1 1 1 ... $ id : chr "AC" "AC" "AC" "AC" ...
source share