Skip to content

Instantly share code, notes, and snippets.

@Ironholds
Last active August 29, 2015 14:05
Show Gist options
  • Select an option

  • Save Ironholds/704f1e070374c32ea829 to your computer and use it in GitHub Desktop.

Select an option

Save Ironholds/704f1e070374c32ea829 to your computer and use it in GitHub Desktop.
SPDF
cdm <- joinCountryData2Map(dF = x, joinCode = "ISO2", nameJoinColumn = "country")
fortified_polygons <- fortify(cdm)
cdm <- as.data.frame(cdm[,c("value")])
fortified_polygons <- merge(fortified_polygons)
> str(x)
'data.frame': 226 obs. of 2 variables:
$ country: chr "AD" "AE" "AF" "AG" ...
$ value : int 350 19655 644 206 1 6770 64038 59 880 123039 ...
> str(cdm)
'data.frame': 244 obs. of 52 variables:
$ ScaleRank : int 1 1 1 1 1 1 1 3 1 1 ...
$ LabelRank : int 1 1 1 1 1 1 1 3 1 1 ...
$ FeatureCla : Factor w/ 2 levels "Adm-0 country",..: 2 2 2 2 2 2 2 2 2 2 ...
$ SOVEREIGNT : Factor w/ 202 levels "Afghanistan",..: 1 5 2 189 8 9 6 60 10 11 ...
$ SOV_A3 : Factor w/ 202 levels "AFG","AGO","ALB",..: 1 2 3 5 6 7 8 61 10 11 ...
$ ADM0_DIF : num 0 0 0 0 0 0 0 1 0 0 ...
$ LEVEL : num 2 2 2 2 2 2 2 2 2 2 ...
$ TYPE : Factor w/ 6 levels "Country","County",..: 6 6 6 6 6 6 5 3 1 6 ...
$ ADMIN : Factor w/ 244 levels "Afghanistan",..: 1 7 3 228 11 12 9 76 15 16 ...
$ ADM0_A3 : Factor w/ 244 levels "ABW","AFG","AGO",..: 2 3 5 8 9 10 12 14 16 17 ...
$ GEOU_DIF : num 0 0 0 0 0 0 0 0 0 0 ...
$ GEOUNIT : Factor w/ 244 levels "Afghanistan",..: 1 7 3 229 11 12 9 76 15 16 ...
$ GU_A3 : Factor w/ 244 levels "ABW","AFG","AGO",..: 2 3 5 8 9 10 12 14 16 17 ...
$ SU_DIF : num 0 0 0 0 0 0 0 0 0 0 ...
$ SUBUNIT : Factor w/ 244 levels "Afghanistan",..: 1 7 3 229 11 12 9 76 15 16 ...
$ SU_A3 : Factor w/ 244 levels "ABW","AFG","AGO",..: 2 3 5 8 9 10 12 14 16 17 ...
$ NAME : Factor w/ 243 levels "Afghanistan",..: 1 7 3 229 11 12 9 75 15 16 ...
$ ABBREV : Factor w/ 240 levels "A.C.Is.","Afg.",..: 2 8 4 222 11 12 9 74 15 14 ...
$ POSTAL : Factor w/ 234 levels "A","AE","AF",..: 3 8 6 2 10 11 9 203 13 1 ...
$ NAME_FORMA : Factor w/ 194 levels "Arab Republic of Egypt",..: 44 75 74 NA 2 76 NA 185 7 77 ...
$ TERR_ : Factor w/ 13 levels "Assoc. with N.Z.",..: NA NA NA NA NA NA 10 9 NA NA ...
$ NAME_SORT : Factor w/ 244 levels "Afghanistan",..: 1 7 3 229 11 12 9 78 15 16 ...
$ MAP_COLOR : num 7 1 6 3 13 10 0 11 7 4 ...
$ POP_EST : num 28400000 12799293 3639453 4798491 40913584 ...
$ GDP_MD_EST : num 22270 110300 21810 184300 573900 ...
$ FIPS_10_ : Factor w/ 3 levels "-99","0","FG": 2 2 2 2 2 2 2 2 2 2 ...
$ ISO_A2 : Factor w/ 236 levels "-99","AD","AE",..: 4 9 7 3 11 8 10 206 14 13 ...
$ ISO_A3 : Factor w/ 244 levels "ABW","AFG","AGO",..: 2 3 6 8 9 10 13 14 16 17 ...
$ ISO_N3 : num 4 24 8 784 32 51 10 260 36 40 ...
$ ISO3 : Factor w/ 244 levels "ABW","AFG","AGO",..: 2 3 6 8 9 10 13 14 16 17 ...
$ LON : num 66.1 17.5 20 54.2 -65.1 ...
$ LAT : num 33.9 -12.3 41.1 23.9 -35.2 ...
$ ISO3.1 : Factor w/ 243 levels "ABW","AFG","AGO",..: 2 3 6 8 9 10 13 14 16 17 ...
$ ADMIN.1 : Factor w/ 243 levels "Afghanistan",..: 1 7 3 227 11 12 9 75 15 16 ...
$ REGION : Factor w/ 7 levels "Africa","Antarctica",..: 3 1 5 3 7 5 2 NA 4 5 ...
$ continent : Factor w/ 6 levels "Africa","Antarctica",..: 4 1 4 4 6 4 2 NA 3 4 ...
$ GEO3major : Factor w/ 7 levels "Africa","Asia and the Pacific",..: 2 1 3 7 4 3 6 NA 2 3 ...
$ GEO3 : Factor w/ 24 levels "Antarctic","Arabian Peninsula",..: 17 20 8 2 16 10 1 NA 3 23 ...
$ IMAGE24 : Factor w/ 26 levels "Antarctica","Asia-Stan",..: 9 21 5 14 18 19 1 NA 16 26 ...
$ GLOCAF : Factor w/ 19 levels "Brazil","Canada",..: 14 17 4 9 13 5 NA NA 11 4 ...
$ Stern : Factor w/ 13 levels "Australasia",..: 4 11 6 13 9 6 NA NA 1 6 ...
$ SRESmajor : Factor w/ 4 levels "ALM","ASIA","OECD90",..: 2 1 4 1 1 4 NA NA 3 3 ...
$ SRES : Factor w/ 11 levels "Central and Eastern Europe (EEU)",..: 9 10 1 4 3 5 NA NA 8 11 ...
$ GBD : Factor w/ 21 levels "Asia Pacific, High Income",..: 4 18 8 15 13 2 NA NA 6 10 ...
$ AVOIDnumeric: int 21 24 25 30 26 25 NA NA 10 25 ...
$ AVOIDname : Factor w/ 30 levels "Australia","Brazil",..: 19 27 7 15 25 7 NA NA 1 7 ...
$ LDC : Factor w/ 2 levels "LDC","other": 1 1 2 2 2 2 2 NA 2 2 ...
$ SID : Factor w/ 2 levels "other","SID": 1 1 1 1 1 1 1 NA 1 1 ...
$ LLDC : Factor w/ 2 levels "LLDC","other": 1 2 2 2 2 1 2 NA 2 2 ...
$ country : chr "AF" "AO" "AL" "AE" ...
$ value : int 644 880 6770 19655 123039 64038 NA NA 279202 126964 ...
$ ISO_A2 : chr "AF" "AO" "AL" "AE" ...
> str(fortified_polygons)
'data.frame': 12374 obs. of 7 variables:
$ long : num 61.2 62.2 63 63.2 64 ...
$ lat : num 35.7 35.3 35.4 35.9 36 ...
$ order: int 1 2 3 4 5 6 7 8 9 10 ...
$ hole : logi FALSE FALSE FALSE FALSE FALSE FALSE ...
$ piece: Factor w/ 30 levels "1","2","3","4",..: 1 1 1 1 1 1 1 1 1 1 ...
$ group: Factor w/ 454 levels "Afghanistan.1",..: 1 1 1 1 1 1 1 1 1 1 ...
$ id : chr "Afghanistan" "Afghanistan" "Afghanistan" "Afghanistan" ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment