Query and visualize data from Statbank Greenland
An implementation of my workflow + experimentation with packages
Explorative analysis of statbank. Heavy use of table ID’s, and querying tidy tables.
Used to be only ggplot2 themes
Used to be (a little) controversial
Not a strict implementation of the API
pxweb
, PxWebApiData
or httr
.Explore contents of Statbank:
# A tibble: 21 × 4
id text type path
<chr> <chr> <chr> <chr>
1 ES Businesses l /ES
2 KR Criminal offenses l /KR
3 UD Education l /UD
4 EN Energy l /EN
5 FI Fisheries and catch l /FI
6 IE Foreign trade l /IE
7 GD Greenlanders in Denmark l /GD
8 SU Health l /SU
9 BO Housing l /BO
10 IN Income l /IN
# ℹ 11 more rows
Use search query to search for table:
# A tibble: 71 × 6
id title type path score published
<chr> <chr> <chr> <chr> <dbl> <chr>
1 BEXCALCS Population Accounts, stock 1981 - t /BE/… 0.894 2023-02-…
2 BEXCALCRS Regional Population Accounts, stock 19… t /BE/… 0.742 2023-02-…
3 SOXOU04 Economically disadvantaged adults by t… t /SO/… 0.308 2022-12-…
4 SUXA3 Abortions by districts and mean popula… t /SU/… 0.293 2023-06-…
5 SOXOU01 Economically disadvantaged by age and … t /SO/… 0.264 2022-12-…
6 SOXOU02 Economically disadvantaged by district… t /SO/… 0.264 2022-12-…
7 BEXSAT1 Population and population growth 1901-… t /BE/… 0.258 2023-02-…
8 BEXCALC2 Population Accounts (consolidated) 198… t /BE/… 0.249 2023-02-…
9 SUXA2 Abortions by age and mean population, … t /SU/… 0.246 2023-06-…
10 SOXOU03 Economically disadvantaged children an… t /SO/… 0.220 2022-12-…
# ℹ 61 more rows
Supports things like wildcard (*
) and fuzzy (~
) searches:
# A tibble: 136 × 6
id title type path score published
<chr> <chr> <chr> <chr> <dbl> <chr>
1 BOXPERS Number of persons per dwelling by dist… t /BO/… 0.816 2015-07-…
2 BEXSTA Population January 1st 1977-2023 t /BE/… 0.408 2023-02-…
3 BEXSTAYY Population January 1st, fixed residenc… t /BE/… 0.408 2023-02-…
4 BEXSTB Population in Municipalities January 1… t /BE/… 0.408 2023-02-…
5 BEXSTC Population in Districts and Municipali… t /BE/… 0.408 2023-02-…
6 BEXSTD Population in Localities January 1st 1… t /BE/… 0.408 2023-02-…
7 BEXSTDt Population seniority in Localities Jan… t /BE/… 0.408 2023-02-…
8 BEXSTNUK Population In Nuuk January 1st by city… t /BE/… 0.408 2023-02-…
9 BEXST6NUK Populaion in Nuuk by Citizenship Janua… t /BE/… 0.408 2023-02-…
10 BEXST2A Population in municipalities(2018) Ja… t /BE/… 0.408 2017-10-…
# ℹ 126 more rows
Specify language or API path:
# A tibble: 8 × 6
id title type path score published
<chr> <chr> <chr> <chr> <dbl> <chr>
1 UDXISCPROD Befolkningens højst fuldførte uddannel… t /UD4… 0.289 2023-08-…
2 UDXISCPROE Befolkningens højst fuldførte uddannel… t /UD4… 0.289 2023-08-…
3 UDXISCPROF Befolkningens højst fuldførte uddannel… t /UD4… 0.289 2023-08-…
4 UDXISCPROG Befolkningens højst fuldførte uddannel… t /UD4… 0.289 2023-08-…
5 UDXISCPROH Befolkningens højst fuldførte uddannel… t /UD4… 0.289 2023-09-…
6 UDXISCPROA Befolkningens uddannelse efter bopæl o… t /UD9… 0.289 2017-08-…
7 UDXISCPROB Befolkningens uddannelse efter alder 2… t /UD9… 0.289 2017-08-…
8 UDXISCPROC Befolkningens uddannelse efter alder o… t /UD9… 0.289 2017-08-…
Folder shorthand shortcut:
# A tibble: 10 × 5
id text type path updated
<chr> <chr> <chr> <chr> <chr>
1 BEXSTA Population January 1st 1977-2023 t /BE/… 2023-0…
2 BEXSTAYY Population January 1st, fixed residence type … t /BE/… 2023-0…
3 BEXSTB Population in Municipalities January 1st 1977… t /BE/… 2023-0…
4 BEXSTC Population in Districts and Municipalities Ja… t /BE/… 2023-0…
5 BEXSTD Population in Localities January 1st 1977-2023 t /BE/… 2023-0…
6 BEXSTDt Population seniority in Localities January 1s… t /BE/… 2023-0…
7 BEXSTE Marital Status by January 1st 1977-2023 t /BE/… 2023-0…
8 BEXSTFSGRL Persons born in Greenland by year of birth an… t /BE/… 2023-0…
9 BEXSTNUK Population In Nuuk January 1st by citydistric… t /BE/… 2023-0…
10 BEXXKIRK Church of Denmark, members 2012 - 2023 t /BE/… 2023-0…
Can explore other pxweb APIs:
Including other statistical offices:
# A tibble: 20 × 4
id text type path
<chr> <chr> <chr> <chr>
1 UO Umhvørvi og orka l /H2/UO
2 IB Íbúgvar og val l /H2/IB
3 AM Arbeiði og lønir l /H2/AM
4 IP Inntøkur og prísir l /H2/IP
5 UV Undirvísing l /H2/UV
6 MM Mentan og átrúnaður l /H2/MM
7 AL Almannamál l /H2/AL
8 HM Heilsumál l /H2/HM
9 RL Rættur og løgregla l /H2/RL
10 SS Samferðsla og samskifti l /H2/SS
11 VV Vinna og veiða l /H2/VV
12 UH Uttanlandshandil l /H2/UH
13 VB Vinnubúskapur l /H2/VB
14 PF Peninga- og fíggjarviðurskifti l /H2/PF
15 LK Lands- og kommunubúskapur l /H2/LK
16 TB Tjóðarbúskapur l /H2/TB
17 KB Konjunkturbarometrið l /H2/KB
18 MT Manntal 2011 l /H2/MT
19 SDG Heimsmálini l /H2/SDG
20 DEV Hagtøl undir menning l /H2/DEV
Lookup url of specific table ID:
[1] "https://bank.stat.gl:443/api/v1/en/Greenland/BE/BE01/BE0120/BEXSTNUK.PX"
In other languages:
Shorthand for translated table:
[1] "https://bank.stat.gl:443/api/v1/da/Greenland/BE/BE01/BE0120/BEXSTNUK.PX"
lang
parameter will always translate:
Works with other API’s too:
First versions of statgl looked like this:
Both use httr
:
statgl_url("BEXSTNUK") %>%
httr::POST(body = statgl:::build_query(list())) %>%
httr::content(as = "text") %>%
rjstat::fromJSONstat() %>%
tibble::as_tibble()
# A tibble: 30 × 1
`Population in Nuuk by time`$time $value
<chr> <int>
1 1994 12483
2 1995 12723
3 1996 12882
4 1997 12909
5 1998 13024
6 1999 13169
7 2000 13445
8 2001 13649
9 2002 13884
10 2003 13884
# ℹ 20 more rows
I would like your feedback on this:
$title
[1] "Nuuks befolkning efter alder, bydel, fødested, køn og tid"
$url
[1] "https://bank.stat.gl:443/api/v1/da/Greenland/BE/BE01/BE0120/BEXSTNUK.PX"
$variables
# A tibble: 5 × 6
code text elimination time values valueTexts
<chr> <chr> <lgl> <lgl> <list> <list>
1 age alder TRUE NA <chr [100]> <chr [100]>
2 citydistrict bydel TRUE NA <chr [6]> <chr [6]>
3 gender køn TRUE NA <chr [3]> <chr [3]>
4 place of birth fødested TRUE NA <chr [3]> <chr [3]>
5 time tid NA TRUE <chr [30]> <chr [30]>
Do you expect something closer to:
$age
[1] "0" "1" "2" "3" "4" "5" "6" "7" "8" "9" "10" "11" "12" "13" "14"
[16] "15" "16" "17" "18" "19" "20" "21" "22" "23" "24" "25" "26" "27" "28" "29"
[31] "30" "31" "32" "33" "34" "35" "36" "37" "38" "39" "40" "41" "42" "43" "44"
[46] "45" "46" "47" "48" "49" "50" "51" "52" "53" "54" "55" "56" "57" "58" "59"
[61] "60" "61" "62" "63" "64" "65" "66" "67" "68" "69" "70" "71" "72" "73" "74"
[76] "75" "76" "77" "78" "79" "80" "81" "82" "83" "84" "85" "86" "87" "88" "89"
[91] "90" "91" "92" "93" "94" "95" "96" "97" "98" "99"
$citydistrict
[1] "N" "1" "2" "3" "4" "9"
$gender
[1] "T" "M" "K"
$`place of birth`
[1] "T" "N" "S"
$time
[1] "1994" "1995" "1996" "1997" "1998" "1999" "2000" "2001" "2002" "2003"
[11] "2004" "2005" "2006" "2007" "2008" "2009" "2010" "2011" "2012" "2013"
[21] "2014" "2015" "2016" "2017" "2018" "2019" "2020" "2021" "2022" "2023"
Output is better suited for statgl_fetch_px()
:
$CHARSET
[1] "ANSI"
$`AXIS-VERSION`
[1] "2010"
$CODEPAGE
[1] "Windows-1252"
$LANGUAGE
[1] "en"
$LANGUAGES
[1] "en,da,kl"
$`CREATION-DATE`
[1] "20190124 09:00"
$DECIMALS
[1] "0"
$SHOWDECIMALS
[1] "0"
$MATRIX
[1] "BEXSTNUK"
$COPYRIGHT
[1] "YES"
$`SUBJECT-CODE`
[1] "BE"
$`SUBJECT-AREA`
[1] "Population"
$DESCRIPTION
[1] "Population In Nuuk January 1st by citydistrict 1994-2023 <em>[BEESTNUK]</em>"
$TITLE
[1] "Population in Nuuk by time"
$CONTENTS
[1] "Population in Nuuk"
$HEADING
[1] "time"
$`VALUES("time")`
[1] "1994,1995,1996,1997,1998,1999,2000,2001,2002,2003,2004,2005,2006,2007,2008,2009,2010,2011,2012,2013,2014,2015,2016,2017,2018,2019,2020,2021,2022,2023"
$`TIMEVAL("time")`
[1] "TLIST(A1),1994,1995,1996,1997,1998,1999,2000,2001,2002,2003,2004,2005,2006,2007,2008,2009,2010,2011,2012,2013,2014,2015,2016,2017,2018,2019,2020,2021,2022,2023"
$`CODES("time")`
[1] "1994,1995,1996,1997,1998,1999,2000,2001,2002,2003,2004,2005,2006,2007,2008,2009,2010,2011,2012,2013,2014,2015,2016,2017,2018,2019,2020,2021,2022,2023"
$`LAST-UPDATED`
[1] "20230210 09:00"
$UNITS
[1] "persons"
$CONTACT
[1] "Lars Pedersen, LARP@stat.gl"
$SOURCE
[1] "Statistics Greenland"
$NOTE
[1] "The Population Register contains information on all persons who have resided in Greenland after 1 January 1977. ##The purpose of the register is to be the basis for population statistics, and to supplement other personal information #with basic informati\r\non about each person, like address and family relations.The Population register is updated with information from CPR (Administrative Population Register) where the following information is retrieved: #name, gender, age, place of birth, citizenship, marit\r\nal status, reference to mother, father and spouse, address of residence and more.#According to §13 of the Act on Greenland Statistics, no person-related information is disclosed from the register, except for personal numbers, randomly drawn for surveys"
$LINK
[1] "www.stat.gl/bee202301/m1"
$`NEXT-UPDATE`
[1] "20240209 09:00"
$`SUBJECT-AREA[da]`
[1] "Befolkning"
$`DESCRIPTION[da]`
[1] "Befolkningen i Nuuks bydele pr 1. januar 1994-2023 <em>[BEDSTNUK]</em>"
$`TITLE[da]`
[1] "Nuuks befolkning efter tid"
$`CONTENTS[da]`
[1] "Nuuks befolkning"
$`HEADING[da]`
[1] "tid"
$`VALUES[da]("tid")`
[1] "1994,1995,1996,1997,1998,1999,2000,2001,2002,2003,2004,2005,2006,2007,2008,2009,2010,2011,2012,2013,2014,2015,2016,2017,2018,2019,2020,2021,2022,2023"
$`TIMEVAL[da]("tid")`
[1] "TLIST(A1),1994,1995,1996,1997,1998,1999,2000,2001,2002,2003,2004,2005,2006,2007,2008,2009,2010,2011,2012,2013,2014,2015,2016,2017,2018,2019,2020,2021,2022,2023"
$`LAST-UPDATED[da]`
[1] "20230210 09:00"
$`UNITS[da]`
[1] "personer"
$`CONTACT[da]`
[1] "Lars Pedersen, LARP@stat.gl"
$`SOURCE[da]`
[1] "Grønlands Statistik"
$`NOTE[da]`
[1] "Befolkningsstatistikregistret indeholder oplysninger om alle personer, som har haft bopæl i Grønland efter 1. januar 1977.##Registrets formål er at danne grundlag for befolkningsstatistikken, samt supplere andre personhenførbare oplysninger #med basisopl\r\nysninger om personen, samt dennes adresse og familierelationer.#Befolkningsstatistikregistret opdateres med oplysninger fra CPR(Folkeregistrene) hvor følgende oplysninger hentes:#navn, køn, alder, fødested, statsborgerskab, civilstand, henvisning til mor\r\n, far samt ægtefælle, bopælsadresse og tilflytningsdato.##Jfr §13 i Lov om Grønlands Statistik, videregives ingen personhenførbare oplysninger fra registret, bortset fra personnumre, som efter Datatilsynets godkendelse er udtrukket til interviewundersøge\r\nlser"
$`LINK[da]`
[1] "www.stat.gl/bed202301/m1"
$`SUBJECT-AREA[kl]`
[1] "Innuttaasut"
$`DESCRIPTION[kl]`
[1] "Nuummi innuttaasut 1994-2023 <em>[BENSTNUK]</em>"
$`TITLE[kl]`
[1] "Nuummi innuttaasut kingorna piffissaq"
$`CONTENTS[kl]`
[1] "Nuummi innuttaasut"
$`HEADING[kl]`
[1] "piffissaq"
$`VALUES[kl]("piffissaq")`
[1] "1994,1995,1996,1997,1998,1999,2000,2001,2002,2003,2004,2005,2006,2007,2008,2009,2010,2011,2012,2013,2014,2015,2016,2017,2018,2019,2020,2021,2022,2023"
$`TIMEVAL[kl]("piffissaq")`
[1] "TLIST(A1),1994,1995,1996,1997,1998,1999,2000,2001,2002,2003,2004,2005,2006,2007,2008,2009,2010,2011,2012,2013,2014,2015,2016,2017,2018,2019,2020,2021,2022,2023"
$`LAST-UPDATED[kl]`
[1] "20230210 09:00"
$`UNITS[kl]`
[1] "inuit amerlassusaat"
$`CONTACT[kl]`
[1] "Lars Pedersen, LARP@stat.gl"
$`SOURCE[kl]`
[1] "Naatsorsueqqissaartarfik"
$`NOTE[kl]`
[1] "Innuttaasunut nalunaarsuisarfik 1.januaari 1977 kingorna Kalaallit Nunaanni najugaqarsimasunut tamanut paasissutissanik imaqarpoq.#Innuttaasut pillugit kisitsisitigut paasissutissaliorsinnaaneq nalunaarsuisarfiup siunertaraa, taamaatullu inunnut tunngasu\r\nnut paasissutissanut allanut tapertaalluni.#Inuup paasissutissaanik tunngaviusunik, kiisali najugaanut ilaqutariinnermilu inissisimaneranut tunngasut.#Innuttaasunut kisitsisitigut paasissutissat nalunaarsuisarfiat paasissutissanit CPR-iminngaanneersunik \r\n(Inunnut nalunaarsuisarfiit) nutarterneqartarpoq tassani paasissutissat pineqartut aaneqarnerisigut:#Ateq, suiaassuseq, ukiut, inunngorfik, innuttaassuseq, aappaqarneq, anaanaasumut, ataataasumut aapparisamullu innersuunneqarneq, najukkami adresse aammal\r\nu qanga nuussimanermut ulloq.##Naatsorsueqqissaartarfik pillugu inatsimmi §13 malillugu inuit ataasiakkaat pillugit paasissutissat nalunaarsuiffinniittut allanut ingerlateqqinneqaqqusaanngillat,taamaallaat inuit normui Datatilsynemit immikkut akuersisoqa\r\nrtillugu apersuinissamut atugassat ingerlateqqinneqarsinnaapput.”"
$`LINK[kl]`
[1] "www.stat.gl/ben202301/m1"
Data querying used to look like this:
And this:
If API is Statbank Greenland and not URL:
px_top()
px_all()
Some values are not shown by default (elimination variables)
.eliminate_rest
can be used to show these quickly:
# A tibble: 38,416 × 6
origin `place of birth` gender distination time value
<chr> <chr> <chr> <chr> <chr> <int>
1 Nanortalik Greenland Men Nanortalik 2022 114
2 Nanortalik Greenland Men Aappilattoq (NAN) 2022 1
3 Nanortalik Greenland Men Narsaq Kujalleq 2022 5
4 Nanortalik Greenland Men Tasiusaq (NAN) 2022 3
5 Nanortalik Greenland Men Illorpaat 2022 0
6 Nanortalik Greenland Men Ammassivik 2022 1
7 Nanortalik Greenland Men Alluitsup Paa 2022 5
8 Nanortalik Greenland Men Andre lokaliteter(NAN) 2022 0
9 Nanortalik Greenland Men Qaqortoq 2022 29
10 Nanortalik Greenland Men Saarloq 2022 1
# ℹ 38,406 more rows
.val_code
shows underlying value codes:
# A tibble: 38,416 × 6
origin `place of birth` gender distination time value
<chr> <chr> <chr> <chr> <chr> <int>
1 9550100NAN N M 9550100NAN 2022 114
2 9550100NAN N M 9550102APL 2022 1
3 9550100NAN N M 9550103NKJ 2022 5
4 9550100NAN N M 9550104TAQ 2022 3
5 9550100NAN N M 9550105ILP 2022 0
6 9550100NAN N M 9550106AMS 2022 1
7 9550100NAN N M 9550108ALP 2022 5
8 9550100NAN N M 9550199X01 2022 0
9 9550100NAN N M 9550200QAQ 2022 29
10 9550100NAN N M 9550201SAL 2022 1
# ℹ 38,406 more rows
.val_code
accepts strings:
statgl_fetch(
"BEXBAF4B", time = px_top(), .eliminate_rest = FALSE,
.val_code = c("origin", "distination")
)
# A tibble: 38,416 × 6
origin `place of birth` gender distination time value
<chr> <chr> <chr> <chr> <chr> <int>
1 9550100NAN Greenland Men 9550100NAN 2022 114
2 9550100NAN Greenland Men 9550102APL 2022 1
3 9550100NAN Greenland Men 9550103NKJ 2022 5
4 9550100NAN Greenland Men 9550104TAQ 2022 3
5 9550100NAN Greenland Men 9550105ILP 2022 0
6 9550100NAN Greenland Men 9550106AMS 2022 1
7 9550100NAN Greenland Men 9550108ALP 2022 5
8 9550100NAN Greenland Men 9550199X01 2022 0
9 9550100NAN Greenland Men 9550200QAQ 2022 29
10 9550100NAN Greenland Men 9550201SAL 2022 1
# ℹ 38,406 more rows
statgl_plot()
statgl_table()
statgl_report()
statgl_map()