Population


library("tidyverse")
library(statgl) # Info at www.stat.gl/SBE202003/o1
library("kableExtra")
library("glue")
library("rjson")


lang <- paste0("?lang=", language) 
select <- "&select"
json <- ".json_stat2"
csv <- ".csv"

first_blank <- c(" " = 1)

table <- "Tabel"
note   <- "Se Statistikbanken tabel: "

title1 <- "1.1. Befolkning i kommuner, distrikter og lokaliteter"

id1 <- "BEDST2"
id2 <- "BEDST3"
id3 <- "BEDST4"


link1 <- "https://bank.stat.gl:443/sq/be66e20d-950c-41fd-98be-0c81e0f19417"
link2 <- "https://bank.stat.gl:443/sq/45b2ccd0-17b0-476c-b7c1-7a92cd5c7a3c" 
link3 <- "https://bank.stat.gl:443/sq/1bb5507d-07ca-4f13-a800-eb873e7c4569"


table1 <- glue("**", table, " 1.** ", fromJSON(file = glue(link1, json, lang))$label)
table2 <- glue("**", table, " 2.** ", fromJSON(file = glue(link2, json, lang))$label)
table3 <- glue("**", table, " 3.** ", fromJSON(file = glue(link3, json, lang))$label)
Population in municipalities, districts and localities
table <- 
  read_csv(
    glue::glue(link1, csv, lang),
    locale = locale(encoding = "latin1"))

column_vector <- 1:8
names(column_vector) <- c(" ",
                          fromJSON(file = glue::glue(link1, json, lang))$dimension$`place of birth`$category$label$N,
                          fromJSON(file = glue::glue(link1, json, lang))$dimension$`place of birth`$category$label$S,
                          fromJSON(file = glue::glue(link1, json, lang))$dimension$`place of birth`$category$label$T,
                          glue(fromJSON(file = glue::glue(link1, json, lang))$dimension$`place of birth`$category$label$N, " "),
                          glue(fromJSON(file = glue::glue(link1, json, lang))$dimension$`place of birth`$category$label$S, " "),
                          glue(fromJSON(file = glue::glue(link1, json, lang))$dimension$`place of birth`$category$label$T, " "),
                          glue(fromJSON(file = glue::glue(link1, json, lang))$dimension$`place of birth`$category$label$T, "  "))

header_vector <- c(1, 3, 3, 1)
names(header_vector) <- c(" ",
                          fromJSON(file = glue::glue(link1, json, lang))$dimension$gender$category$label$M,
                          fromJSON(file = glue::glue(link1, json, lang))$dimension$gender$category$label$K,
                          fromJSON(file = glue::glue(link1, json, lang))$dimension$gender$category$label$T)

table %>% 
  select(-8, -9) %>% 
  rename(column_vector) %>% 
  statgl_table() %>% 
  row_spec(1, bold = T) %>% 
  add_header_above(header_vector)
Men
Women
Total
Greenland Born outside Greenland Total Greenland Born outside Greenland Total Total
Total 25.701 4.170 29.871 24.459 2.279 26.738 56.609
Kommune Kujalleq 3.020 266 3.286 2.794 125 2.919 6.205
Kommuneqarfik Sermersooq 9.977 2.731 12.708 9.925 1.515 11.440 24.148
Qeqqata Kommunia 4.366 442 4.808 4.134 249 4.383 9.191
Kommune Qeqertalik 3.079 167 3.246 2.752 84 2.836 6.082
Avannaata Kommunia 5.247 530 5.777 4.844 299 5.143 10.920
Outside municipalities 12 34 46 10 7 17 63


Se Statistikbanken tabel: BEDST2

table <- 
  read_csv(
    glue::glue(link2, csv, lang),
    locale = locale(encoding = "latin1"))

column_vector <- 1:8
names(column_vector) <- c(" ",
                          fromJSON(file = glue::glue(link2, json, lang))$dimension$`place of birth`$category$label$N,
                          fromJSON(file = glue::glue(link2, json, lang))$dimension$`place of birth`$category$label$S,
                          fromJSON(file = glue::glue(link2, json, lang))$dimension$`place of birth`$category$label$T,
                          glue(fromJSON(file = glue::glue(link2, json, lang))$dimension$`place of birth`$category$label$N, " "),
                          glue(fromJSON(file = glue::glue(link2, json, lang))$dimension$`place of birth`$category$label$S, " "),
                          glue(fromJSON(file = glue::glue(link2, json, lang))$dimension$`place of birth`$category$label$T, " "),
                          glue(fromJSON(file = glue::glue(link2, json, lang))$dimension$`place of birth`$category$label$T, "  "))

header_vector <- c(1, 3, 3, 1)
names(header_vector) <- c(" ",
                          fromJSON(file = glue::glue(link2, json, lang))$dimension$gender$category$label$M,
                          fromJSON(file = glue::glue(link2, json, lang))$dimension$gender$category$label$K,
                          fromJSON(file = glue::glue(link2, json, lang))$dimension$gender$category$label$T)


table %>% 
  select(-8, -9) %>% 
  filter(table[,10] > 0) %>% 
  rename(column_vector) %>% 
  statgl_table() %>% 
  row_spec(1, bold = T) %>% 
  add_header_above(header_vector)
Men
Women
Total
Greenland Born outside Greenland Total Greenland Born outside Greenland Total Total
Total 25.701 4.170 29.871 24.459 2.279 26.738 56.609
Nanortalik 809 37 846 673 14 687 1.533
Qaqortoq 1.464 175 1.639 1.408 77 1.485 3.124
Narsaq 747 54 801 713 34 747 1.548
Paamiut 670 25 695 536 14 550 1.245
Nuuk 7.824 2.613 10.437 7.932 1.455 9.387 19.824
Maniitsoq 1.546 110 1.656 1.365 51 1.416 3.072
Sisimiut 2.820 332 3.152 2.769 198 2.967 6.119
Kangaatsiaq 591 5 596 495 3 498 1.094
Aasiaat 1.485 138 1.623 1.327 68 1.395 3.018
Qasigiannguit 568 12 580 525 8 533 1.113
Ilulissat 2.336 411 2.747 2.242 230 2.472 5.219
Qeqertarsuaq 435 12 447 405 5 410 857
Uummannaq 1.088 69 1.157 1.031 46 1.077 2.234
Upernavik 1.433 40 1.473 1.226 16 1.242 2.715
Qaanaaq 390 10 400 345 7 352 752
Tasiilaq 1.307 82 1.389 1.299 37 1.336 2.725
Ittoqqortoormiit 176 11 187 158 9 167 354


Se Statistikbanken tabel: BEDST3

table <- 
  read_csv(
    glue(link3, csv, lang),
    locale = locale(encoding = "latin1"))

column_vector <- 1:8
names(column_vector) <- c(" ",
                          fromJSON(file = glue::glue(link3, json, lang))$dimension$`place of birth`$category$label$N,
                          fromJSON(file = glue::glue(link3, json, lang))$dimension$`place of birth`$category$label$S,
                          fromJSON(file = glue::glue(link3, json, lang))$dimension$`place of birth`$category$label$T,
                          glue(fromJSON(file = glue::glue(link3, json, lang))$dimension$`place of birth`$category$label$N, " "),
                          glue(fromJSON(file = glue::glue(link3, json, lang))$dimension$`place of birth`$category$label$S, " "),
                          glue(fromJSON(file = glue::glue(link3, json, lang))$dimension$`place of birth`$category$label$T, " "),
                          glue(fromJSON(file = glue::glue(link3, json, lang))$dimension$`place of birth`$category$label$T, "  "))

header_vector <- c(1, 3, 3, 1)
names(header_vector) <- c(" ",
                          fromJSON(file = glue::glue(link3, json, lang))$dimension$gender$category$label$M,
                          fromJSON(file = glue::glue(link3, json, lang))$dimension$gender$category$label$K,
                          fromJSON(file = glue::glue(link3, json, lang))$dimension$gender$category$label$T)

table %>% 
    select(-8, -9) %>% 
    filter(table[,10] > 0) %>% 
    rename(column_vector) %>% 
    statgl_table() %>% 
    row_spec(1, bold = T) %>% 
    add_header_above(header_vector)
Men
Women
Total
Greenland Born outside Greenland Total Greenland Born outside Greenland Total Total
Total 25.701 4.170 29.871 24.459 2.279 26.738 56.609
Nanortalik (town) 582 28 610 496 13 509 1.119
Aappilattoq (settlement in Kujalleq) 52 1 53 39 1 40 93
Narsarmijit 28 1 29 28 0 28 57
Tasiusaq (settlement in Kujalleq) 37 0 37 19 0 19 56
Ammassivik (settlement) 23 0 23 20 0 20 43
Alluitsup Paa (settlement) 87 6 93 71 0 71 164
Uoplyst i Nanortalik distrikt 0 1 1 0 0 0 1
Qaqortoq (town) 1.396 171 1.567 1.362 76 1.438 3.005
Saarloq (settlement) 16 0 16 10 0 10 26
Eqalugaarsuit (settlement) 42 3 45 33 1 34 79
Qassimiut (settlement) 10 1 11 3 0 3 14
Narsaq (town) 634 36 670 617 25 642 1.312
Igaliku (settlement) 21 1 22 12 1 13 35
Qassiarsuk (settlement) 33 1 34 26 2 28 62
Narsarsuaq (settlement) 59 16 75 58 6 64 139
Paamiut (town) 632 25 657 505 11 516 1.173
Arsuk (settlement) 38 0 38 31 3 34 72
Nuuk (town) 7.698 2.611 10.309 7.842 1.453 9.295 19.604
Qeqertarsuatsiaat (settlement) 101 1 102 74 1 75 177
Kapisillit (settlement) 25 1 26 16 1 17 43
Tasiilaq (town) 887 67 954 918 32 950 1.904
Sermiligaaq (settlement) 95 1 96 93 0 93 189
Isertoq (settlement) 34 0 34 29 0 29 63
Kulusuk (settlement) 121 9 130 91 5 96 226
Tiilerilaaq (settlement) 42 2 44 49 0 49 93
Kuummiit (settlement) 128 3 131 119 0 119 250
Ittoqqortoormiit (town) 176 9 185 158 9 167 352
Nerlerit Inaat (Airport) 0 1 1 0 0 0 1
Uoplyst i Illoqqortoormiut distrikt 0 1 1 0 0 0 1
Maniitsoq (town) 1.245 107 1.352 1.116 51 1.167 2.519
Atammik (settlement) 104 2 106 86 0 86 192
Napasoq (settlement) 34 0 34 36 0 36 70
Kangaamiut (settlement) 163 1 164 127 0 127 291
Sisimiut (town) 2.530 248 2.778 2.481 177 2.658 5.436
Itilleq (settlement) 49 0 49 42 0 42 91
Sarfannguit (settlement) 55 0 55 46 0 46 101
Kangerlussuaq (settlement) 186 84 270 200 21 221 491
Kangaatsiaq (town) 270 3 273 231 3 234 507
Attu (settlement) 110 1 111 85 0 85 196
Iginniarfik (settlement) 35 0 35 29 0 29 64
Niaqornaarsuk (settlement) 127 0 127 106 0 106 233
Ikerasaarsuk (KAN)(settlement) 49 1 50 44 0 44 94
Aasiaat (town) 1.415 138 1.553 1.282 68 1.350 2.903
Akunnaaq (settlement) 40 0 40 21 0 21 61
Kitsissuarsuit (settlement) 30 0 30 24 0 24 54
Qasigiannguit (town) 531 12 543 487 7 494 1.037
Ikamiut (settlement) 37 0 37 38 1 39 76
Qeqertarsuaq (town) 428 12 440 400 5 405 845
Kangerluk (settlement) 7 0 7 5 0 5 12
Ilulissat (town) 2.142 404 2.546 2.077 225 2.302 4.848
Oqaatsut (settlement) 24 4 28 19 1 20 48
Qeqertaq (settlement) 57 1 58 53 1 54 112
Saqqaq (settlement) 89 2 91 67 2 69 160
Ilimanaq (settlement) 24 0 24 26 1 27 51
Uummannaq (town) 666 57 723 646 38 684 1.407
Niaqornat (settlement) 15 0 15 19 0 19 34
Qaarsut (settlement) 78 2 80 80 1 81 161
Ikerasak (settlement) 121 0 121 108 0 108 229
Saattut (settlement) 135 6 141 113 5 118 259
Ukkusissat (settlement) 73 4 77 65 2 67 144
Upernavik (town) 576 28 604 477 9 486 1.090
Upernavik Kujalleq (settlement) 104 0 104 97 0 97 201
Kangersuatsiaq (settlement) 85 0 85 56 0 56 141
Aappilattoq (settlement in Avannaa) 78 0 78 71 0 71 149
Tasiusaq (settlement in Avannaa) 125 4 129 116 4 120 249
Nuussuaq (settlement) 93 0 93 88 0 88 181
Kullorsuaq (settlement) 222 5 227 215 2 217 444
Naajaat (settlement) 25 0 25 20 0 20 45
Innaarsuit (settlement) 99 3 102 68 1 69 171
Nutaarmiut (settlement) 25 0 25 18 0 18 43
Ikerasaarsuk (UPE)(settlement) 1 0 1 0 0 0 1
Qaanaaq (town) 317 9 326 296 7 303 629
Savissivik (settlement) 32 0 32 18 0 18 50
Siorapaluk (settlement) 24 1 25 16 0 16 41
Qeqertat (settlement) 16 0 16 15 0 15 31
Uoplyst i Qaanaaq distrikt 1 0 1 0 0 0 1
Pituffik (Station) 12 26 38 9 4 13 51
Uoplyst udenfor kommunerne 0 8 8 1 3 4 12


Se Statistikbanken tabel: BEDST4


Last updated: 06. juni 2023
LS0tDQpwYXJhbXM6DQogIGxhbmc6ICJkYSINCm91dHB1dDoNCiAgc3RhdGdsOjpzdGF0Z2xfcmVwb3J0Og0KICAgIGFuY2hvcl9zZWN0aW9uczogZmFsc2UNCiAgICBjb2RlX2Rvd25sb2FkOiB0cnVlDQogICAgY29kZV9mb2xkaW5nOiBoaWRlDQplZGl0b3Jfb3B0aW9uczogDQogIGNodW5rX291dHB1dF90eXBlOiBjb25zb2xlDQotLS0NCg0KYGBge3Igc2V0dXAsIGluY2x1ZGU9RkFMU0V9DQoNCmtuaXRyOjpvcHRzX2NodW5rJHNldCgNCgllY2hvICAgID0gVFJVRSwNCgltZXNzYWdlID0gRkFMU0UsDQoJd2FybmluZyA9IEZBTFNFLA0KCWNsYXNzLm91dHB1dCA9ICJzY3JvbGwtMTAwIg0KKQ0KDQp7DQpsaWJyYXJ5KCJ0aWR5dmVyc2UiKQ0KbGlicmFyeSgic3RhdGdsIikNCmxpYnJhcnkoImthYmxlRXh0cmEiKQ0KbGlicmFyeSgibHVicmlkYXRlIik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