library(statgl)
statgl_fetch(
"BEXSTA",
time = px_top(15),
.lang = "en",
.col_code = TRUE
) |>
statgl_plot(
x = time,
title = "Befolkningen",
subtitle = "Seneste 15 år"
)The Statbank
Statistics Greenland collects, processes and publishes statistics on social conditions in Greenland. The purpose is to ensure a solid data basis for the population, the business sector, political decisions, analyses and social science research.
bank.stat.gl is the entry point to the public table collection of Statistics Greenland, the Statbank.
The Statbank contains the tables that are published on an ongoing basis by Statistics Greenland. The tables are updated in connection with new releases, and we aim to make them available in Greenlandic, Danish and English.
The Statbank is based on the software PxWeb, which is developed by Statistics Sweden (SCB) in cooperation with other statistical organisations. PxWeb is used by a number of national and regional statistical offices. Many of the principles for finding, selecting and retrieving data can therefore be reused in other PxWeb-based statbanks.
How to use the Statbank
The usual workflow is:
- Find a table
- select subject
- select table
- Select the desired variables and values
- Retrieve the table
- Add calculations or other post-processing if needed
- Show the result as a chart if needed
- Select Save your table if the extract is to be used again
Save your table
With Save your table, a specific table extract can be saved as a link. The link can be used again later and can also be used from, for example, Excel, R or Python.
When a saved query is created, you can, among other things, decide how the extract should handle future updates.
See Saved queries and API for guidance on saved queries, language, file formats, documentation of table extracts and direct use of the Statbank API.
Use the Statbank from R
Data from the Statbank can be retrieved directly in R. Statistics Greenland develops the package statgl, which contains functions for retrieving data from PxWeb-based statbanks and for presenting tables and charts.
pxmake is developed by Statistics Greenland and is made freely available on CRAN. The package is used to produce and maintain files in (.px format) from R and is part of the production of tables for the Statbank of Statistics Greenland.
Installation
statgl is installed from GitHub:
install.packages("remotes")
remotes::install_github("StatisticsGreenland/statgl")pxmake is available on CRAN:
install.packages("pxmake")Retrieve a table with statgl
Tables can be retrieved directly using the table id. Here the latest 15 years are retrieved from the population table BEXSTA:
library(statgl)
bef <- statgl_fetch(
"BEXSTA",
time = px_top(15),
.lang = "en",
.col_code = TRUE
)
befpx_top(15) here means the latest 15 periods. With .lang = "en" Danish texts are retrieved, while .col_code = TRUE keeps the fixed variable codes as column names.
Show the result as a chart
The result from statgl_fetch() can be passed directly on to statgl_plot():
statgl_plot() chooses a suitable chart type based on the data and the specified variables. A time series is shown as a line chart.
Use a saved query from R
A saved query can also be read directly into R. If the extract is to be used as CSV, .csv can be added to the link:
url <- paste0(
"https://bank.stat.gl:443/sq/",
"4772114d-4c69-4023-bee3-399e84ab5382.csv?lang=da"
)
data <- read.csv(
url,
check.names = FALSE
)With pxmake, the same saved query can be retrieved as a PC-Axis file by adding .px to the link:
library(pxmake)
px_url <- paste0(
"https://bank.stat.gl:443/sq/",
"4772114d-4c69-4023-bee3-399e84ab5382.px?lang=da"
)
x <- px(px_url)x contains both data and metadata from the table extract and can then be examined, changed or saved again with the functions in pxmake.
This is practical when an extract first has to be defined manually in the Statbank and then reused in an R script. See Saved queries and API for choice of language, updating and documentation of the saved query.
Work with PX files using pxmake
pxmake is relevant when you need to work directly with the PC-Axis format. An existing PX file can, for example, be read like this:
library(pxmake)
x <- px("min_tabel.px")A dataset can also be converted into a PX object and saved as a PX file:
x <- px(mine_data)
px_save(
x,
"min_tabel.px"
)The package also contains functions for working with metadata such as title, contents, units, variables, values and codes.
The text on this page was translated with AI assistance. Graphs, tables and key figures are not AI-generated.