geofi R-package for accessing Statistics Finland spatial data

[This article was first published on rOpenGov R packages for open government data analytics, and kindly contributed to R-bloggers]. (You can report issue about the content on this page here)
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

We have slowly started developing a follow-up package with ropengov-posse for gisfin-package named geofi. Package provides access to few sources of Finnish open geospatial data from R. We are focusing in administrative regions at the moment and our primary source of data is Statistics Finland and their wfs-api. You can use functions in geofi fecth data such as municipality borders, postal code areas sekä population grids.

geofi is not published in CRAN yet and you cant install it using install.packages(). But you can install it directly from Github with remotes::install_github("ropengov/geofi") and try out the following examples. For quick access try our Shiny app at:

Municipalility borders


municipalities <- get_municipalities(year = 2020, scale = 4500)
ggplot(municipalities) + 
  geom_sf(aes(fill = as.integer(kunta))) +

Postal code areas

zipcodes <- get_zipcodes(year = 2020) 
ggplot(zipcodes) + 
  geom_sf(aes(fill = as.integer(posti_alue)), color = alpha("white", 1/3)) +

Population grids

pop_grid <- get_population_grid(year = 2018, resolution = 5)
ggplot(pop_grid) + 
  geom_sf(aes(fill = objectid), color = alpha("white", 1/3)) +

Regions (maakunnant), health care districts (sairaanhoitopiirit) and many more regional breakdowns are based on municipality divide. get_municipalities()-function returns data containing these attribute variables (year 2020), that you can use to aggregate from municipality level upwards.

municipalities <- get_municipalities(year = 2019, scale = 4500)
regions <- municipalities %>% 
  group_by(maakunta_name_fi) %>% summarise()
ggplot(regions) + 
  geom_sf(aes(fill = maakunta_name_fi)) +

You can join geofi datas with other attribute, too. Below is an example on how to get (non-spatial statistical) data from Statistics Finland and create a map on population at municipality level.


municipalities17 <- get_municipalities(year = 2017)

# pull municipality data from Statistics Finland
pxweb_query_list <-
  list("Alue 2019"=c("*"),
px_data <-
  pxweb_get(url = "",
            query = pxweb_query_list)
# Convert to data.frame
tk_data <-, = "text", variable.value.type = "text")
tk_data2 <- tk_data %>%
  rename(name = `Alue 2019`) %>%
  mutate(name = as.character(name),
         # Paste Tiedot and Vuosi
         Tiedot = paste(Tiedot, Vuosi)) %>%
  select(-Vuosi) %>%
  spread(Tiedot, `Kuntien avainluvut`) %>%
tk_data3 <- janitor::clean_names(tk_data2)

# Join with Statistics Finland attribute data
dat <- left_join(municipalities17, tk_data3)

ggplot(dat) + 
  geom_sf(aes(fill = vakiluku_2017), color = alpha("white", 1/3)) +
  scale_fill_viridis_c(trans = "sqrt")

Take a look at the Github-site and join us!

To leave a comment for the author, please follow the link and comment on their blog: rOpenGov R packages for open government data analytics. offers daily e-mail updates about R news and tutorials about learning R and many other topics. Click here if you're looking to post or find an R/data-science job.
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

Never miss an update!
Subscribe to R-bloggers to receive
e-mails with the latest R posts.
(You will not see this message again.)

Click here to close (This popup will not appear again)