library(rnaturalearth)
<- ne_countries(scale = "medium",
mapdata returnclass = "sf")
10 Inspecting Geographic Data Files
Often, when we open a new geographic data file, we don’t know what fields of data it contains.
It is useful to get an idea of what data our geographic data file already contains in order to know whether or not we may need to merge in other data (Chapter 15).
names
and head
are two useful commands for learning about new geographic data files.
As an example, I am going to use the country data from the rnaturalearth
library (Chapter 12).
10.1 Data
I use ne_countries()
to create the mapdata
dataset as an sf
object (Chapter 7).
10.2 names
names
gives us the names of all of the fields of the data.
names(mapdata)
[1] "scalerank" "featurecla" "labelrank" "sovereignt" "sov_a3"
[6] "adm0_dif" "level" "type" "admin" "adm0_a3"
[11] "geou_dif" "geounit" "gu_a3" "su_dif" "subunit"
[16] "su_a3" "brk_diff" "name" "name_long" "brk_a3"
[21] "brk_name" "brk_group" "abbrev" "postal" "formal_en"
[26] "formal_fr" "note_adm0" "note_brk" "name_sort" "name_alt"
[31] "mapcolor7" "mapcolor8" "mapcolor9" "mapcolor13" "pop_est"
[36] "gdp_md_est" "pop_year" "lastcensus" "gdp_year" "economy"
[41] "income_grp" "wikipedia" "fips_10" "iso_a2" "iso_a3"
[46] "iso_n3" "un_a3" "wb_a2" "wb_a3" "woe_id"
[51] "adm0_a3_is" "adm0_a3_us" "adm0_a3_un" "adm0_a3_wb" "continent"
[56] "region_un" "subregion" "region_wb" "name_len" "long_len"
[61] "abbrev_len" "tiny" "homepart" "geometry"
10.3 head
head
shows us the first several rows of data.
head(mapdata)
Simple feature collection with 6 features and 63 fields
Geometry type: MULTIPOLYGON
Dimension: XY
Bounding box: xmin: -70.06611 ymin: -18.01973 xmax: 74.89131 ymax: 60.40581
Geodetic CRS: +proj=longlat +datum=WGS84 +no_defs +ellps=WGS84 +towgs84=0,0,0
scalerank featurecla labelrank sovereignt sov_a3 adm0_dif level
0 3 Admin-0 country 5 Netherlands NL1 1 2
1 1 Admin-0 country 3 Afghanistan AFG 0 2
2 1 Admin-0 country 3 Angola AGO 0 2
3 1 Admin-0 country 6 United Kingdom GB1 1 2
4 1 Admin-0 country 6 Albania ALB 0 2
5 3 Admin-0 country 6 Finland FI1 1 2
type admin adm0_a3 geou_dif geounit gu_a3 su_dif
0 Country Aruba ABW 0 Aruba ABW 0
1 Sovereign country Afghanistan AFG 0 Afghanistan AFG 0
2 Sovereign country Angola AGO 0 Angola AGO 0
3 Dependency Anguilla AIA 0 Anguilla AIA 0
4 Sovereign country Albania ALB 0 Albania ALB 0
5 Country Aland ALD 0 Aland ALD 0
subunit su_a3 brk_diff name name_long brk_a3 brk_name
0 Aruba ABW 0 Aruba Aruba ABW Aruba
1 Afghanistan AFG 0 Afghanistan Afghanistan AFG Afghanistan
2 Angola AGO 0 Angola Angola AGO Angola
3 Anguilla AIA 0 Anguilla Anguilla AIA Anguilla
4 Albania ALB 0 Albania Albania ALB Albania
5 Aland ALD 0 Aland Aland Islands ALD Aland
brk_group abbrev postal formal_en formal_fr note_adm0
0 <NA> Aruba AW Aruba <NA> Neth.
1 <NA> Afg. AF Islamic State of Afghanistan <NA> <NA>
2 <NA> Ang. AO People's Republic of Angola <NA> <NA>
3 <NA> Ang. AI <NA> <NA> U.K.
4 <NA> Alb. AL Republic of Albania <NA> <NA>
5 <NA> Aland AI Åland Islands <NA> Fin.
note_brk name_sort name_alt mapcolor7 mapcolor8 mapcolor9 mapcolor13
0 <NA> Aruba <NA> 4 2 2 9
1 <NA> Afghanistan <NA> 5 6 8 7
2 <NA> Angola <NA> 3 2 6 1
3 <NA> Anguilla <NA> 6 6 6 3
4 <NA> Albania <NA> 1 4 1 6
5 <NA> Aland <NA> 4 1 4 6
pop_est gdp_md_est pop_year lastcensus gdp_year economy
0 103065 2258.0 NA 2010 NA 6. Developing region
1 28400000 22270.0 NA 1979 NA 7. Least developed region
2 12799293 110300.0 NA 1970 NA 7. Least developed region
3 14436 108.9 NA NA NA 6. Developing region
4 3639453 21810.0 NA 2001 NA 6. Developing region
5 27153 1563.0 NA NA NA 2. Developed region: nonG7
income_grp wikipedia fips_10 iso_a2 iso_a3 iso_n3 un_a3 wb_a2
0 2. High income: nonOECD NA <NA> AW ABW 533 533 AW
1 5. Low income NA <NA> AF AFG 004 004 AF
2 3. Upper middle income NA <NA> AO AGO 024 024 AO
3 3. Upper middle income NA <NA> AI AIA 660 660 <NA>
4 4. Lower middle income NA <NA> AL ALB 008 008 AL
5 1. High income: OECD NA <NA> AX ALA 248 248 <NA>
wb_a3 woe_id adm0_a3_is adm0_a3_us adm0_a3_un adm0_a3_wb continent
0 ABW NA ABW ABW NA NA North America
1 AFG NA AFG AFG NA NA Asia
2 AGO NA AGO AGO NA NA Africa
3 <NA> NA AIA AIA NA NA North America
4 ALB NA ALB ALB NA NA Europe
5 <NA> NA ALA ALD NA NA Europe
region_un subregion region_wb name_len long_len
0 Americas Caribbean Latin America & Caribbean 5 5
1 Asia Southern Asia South Asia 11 11
2 Africa Middle Africa Sub-Saharan Africa 6 6
3 Americas Caribbean Latin America & Caribbean 8 8
4 Europe Southern Europe Europe & Central Asia 7 7
5 Europe Northern Europe Europe & Central Asia 5 13
abbrev_len tiny homepart geometry
0 5 4 NA MULTIPOLYGON (((-69.89912 1...
1 4 NA 1 MULTIPOLYGON (((74.89131 37...
2 4 NA 1 MULTIPOLYGON (((14.19082 -5...
3 4 NA NA MULTIPOLYGON (((-63.00122 1...
4 4 NA 1 MULTIPOLYGON (((20.06396 42...
5 5 5 NA MULTIPOLYGON (((20.61133 60...