fhimaps is a package for map visualisation developed by researchers at Norwegian Institute of Public Health (Folkehelseinstituttet, FHI). The package contains map data for Norway at different levels geographic granularity and layout.

name scope geographic_granularity type border layout R class
norway_lau2_map_b2019_default_dt norway lau2 map 2019 default data.table
norway_lau2_map_b2019_default_sf norway lau2 map 2019 default sf
norway_lau2_map_b2019_insert_oslo_dt norway lau2 map 2019 insert_oslo data.table
norway_lau2_map_b2020_default_dt norway lau2 map 2020 default data.table
norway_lau2_map_b2020_default_sf norway lau2 map 2020 default sf
norway_lau2_map_b2020_insert_oslo_dt norway lau2 map 2020 insert_oslo data.table
norway_lau2_map_b2020_split_dt norway lau2 map 2020 split data.table
norway_nuts3_map_b2017_default_dt norway nuts3 map 2017 default data.table
norway_nuts3_map_b2017_default_sf norway nuts3 map 2017 default sf
norway_nuts3_map_b2017_insert_oslo_dt norway nuts3 map 2017 insert_oslo data.table
norway_nuts3_map_b2019_default_dt norway nuts3 map 2019 default data.table
norway_nuts3_map_b2019_default_sf norway nuts3 map 2019 default sf
norway_nuts3_map_b2019_insert_oslo_dt norway nuts3 map 2019 insert_oslo data.table
norway_nuts3_map_b2020_default_dt norway nuts3 map 2020 default data.table
norway_nuts3_map_b2020_default_sf norway nuts3 map 2020 default sf
norway_nuts3_map_b2020_insert_oslo_dt norway nuts3 map 2020 insert_oslo data.table
norway_nuts3_map_b2020_split_oslo_dt norway nuts3 map 2020 split data.table
norway_nuts3_position_geolabels_b2017_default_dt norway nuts3 position_geolabels 2017 default data.table
norway_nuts3_position_geolabels_b2019_default_dt norway nuts3 position_geolabels 2019 default data.table
norway_nuts3_position_geolabels_b2020_default_dt norway nuts3 position_geolabels 2020 default data.table
norway_nuts3_position_geolabels_b2020_insert_oslo_dt norway nuts3 position_geolabels 2020 insert_oslo data.table
norway_lau2_position_geolabels_b2020_default_dt norway lau2 position_geolabels 2020 default data.table
norway_lau2_position_geolabels_b2020_insert_oslo_dt norway lau2 position_geolabels 2020 insert_oslo data.table
norway_xxx_position_title_insert_oslo_b2017_insert_oslo_dt norway xxx position_title_insert_oslo 2017 insert_oslo data.table
norway_xxx_position_title_insert_oslo_b2019_insert_oslo_dt norway xxx position_title_insert_oslo 2019 insert_oslo data.table
norway_xxx_position_title_insert_oslo_b2020_insert_oslo_dt norway xxx position_title_insert_oslo 2020 insert_oslo data.table
oslo_ward_map_b2020_default_dt oslo ward map 2020 default data.table
oslo_ward_map_b2020_default_sf oslo ward map 2020 default sf
oslo_ward_position_geolabels_b2020_default_dt oslo ward position_geolabels 2020 default data.table

Naming scheme

The naming scheme has the following pattern: scope_geogranularity_type_border_layout_Rclass.

Scope

This is what content the map data contains. Currently we focus on these 2 scopes:

  • country (Norway)
  • city (Oslo)

Geogranularity

This is the geographic granularity, which defines the border of county, municipality and ward. We follow the EU definition of territorial unit (NUTS, LAU) when applicable.

  • NUTS3: Nomenclature of Territorial Unit level 3. Equivalent to fylke (county) in Norway.

  • LAU2: Local Administrative Unit level 2. Equivalent to kommune (municipality) in Norway.

  • ward: district within a municipality. Bydel in Norwegian. So far we only have the data for Oslo.

  • xxx: only used for plotting position_title. (see example)

Type

The type of the data object to distinguish whether it’s a geographical map or coordinate for label positions.

  • map: map data, in either data.table or sf class.

  • position geolabels: geographical coordinates for the position of labels, e.g. “county03” or “Oslo”.

  • position title (insert oslo): geographical coordinate for position of title. So far it’s only for layout: insert_oslo. (see example)

Border

Due to recent redistricting, there exist multiple versions of county borders. We provide maps that match the borders in the following years:

  • 2020: the current border, this map contains 11 counties.

  • 2019: border before redistricting in 2020. This map contains 19 counties.

  • 2017: border before redistricting in 2018.

More information on counties in Norway can be found here.

Layout

Map layout, see this section for examples.

R class

R class for the map object.

  • data.table: applicable for maps and label/title coordinates.

  • sf: simple feature for spatial vector data. More on sf.

Examples

This section provides examples on:

  • Layout options

  • Customization with color and label

  • sf for interactive maps

Set up

library(fhimaps)
#> fhimaps 2021.8.5 https://folkehelseinstituttet.github.io/fhimaps
library(ggplot2)
library(data.table)
library(magrittr)

Layout options

We have 3 layout options for Norway map: default, split and insert Oslo.

For Oslo county map, we only have the default layout.

Norway layout: default

pd <- copy(fhimaps::norway_lau2_map_b2020_default_dt)
q <- ggplot()
q <- q + geom_polygon(data = pd, aes( x = long, y = lat, group = group), 
                      color="black", fill="white", size=0.1)
q <- q + theme_void()
q <- q + coord_quickmap()
q <- q + labs(title = "Default layout")
q

Norway layout: split

pd <- copy(fhimaps::norway_lau2_map_b2020_split_dt)
q <- ggplot()
q <- q + geom_polygon(data = pd, aes( x = long, y = lat, group = group), 
                      color="black", fill="white", size=0.1)
q <- q + theme_void()
q <- q + coord_quickmap()
q <- q + labs(title = "Split layout")
q

Norway layout: insert oslo

pd <- copy(fhimaps::norway_lau2_map_b2020_insert_oslo_dt)
q <- ggplot()
q <- q + geom_polygon(data = pd, aes( x = long, y = lat, group = group), 
                      color="black", fill="white", size=0.1)

# add title "Oslo"
q <- q + annotate(
  "text", 
  x = fhimaps::norway_xxx_position_title_insert_oslo_b2020_insert_oslo_dt$long, 
  y = fhimaps::norway_xxx_position_title_insert_oslo_b2020_insert_oslo_dt$lat,
  label = "Oslo"
  )
q <- q + theme_void()
q <- q + coord_quickmap()
q <- q + labs(title = "Insert Oslo layout")
q

Oslo ward layout: default

pd <- copy(fhimaps::oslo_ward_map_b2020_default_dt)
q <- ggplot()
q <- q + geom_polygon(data = pd, aes(x = long, y = lat, group = group), 
                      color="black", fill="white", size=0.1)
q <- q + theme_void()
q <- q + coord_quickmap()
q <- q + labs(title = "Oslo wards")
q

Customise the maps

The maps can be easily customized with color and labels.

Automatic coloring by location_code

pd <- copy(fhimaps::norway_nuts3_map_b2020_insert_oslo_dt)

q <- ggplot()
q <- q + geom_polygon(
  data = pd, 
  mapping = aes(
    x = long, 
    y = lat,
    group = group,
    fill = location_code
  ),  
  color="black",
  size=0.1
)
q <- q + annotate(
  "text",
  x = fhimaps::norway_xxx_position_title_insert_oslo_b2020_insert_oslo_dt$long,
  y = fhimaps::norway_xxx_position_title_insert_oslo_b2020_insert_oslo_dt$lat,
  label = "Oslo"
)
q <- q + theme_void()
q <- q + coord_quickmap()
q <- q + labs(title = "")
q

Customized coloring with external information

It is also possible to specify the color by user-defined groups. Here we show an example of assigning different (pseudo) risk level to each county.

pd <- copy(fhimaps::norway_nuts3_map_b2020_insert_oslo_dt)

# assign each location a random category for different colors
location_info <- unique(pd[,c("location_code")])
location_info[,category:=rep(
  c("Good","Normal","Neutral","Bad","Very Bad"),
  each=3)[1:.N]
]
location_info[,category:=factor(
  category,
  levels=c("Good","Normal","Neutral","Bad","Very Bad")
  )
]
print(location_info)
#>     location_code category
#>  1:      county11     Good
#>  2:      county15     Good
#>  3:      county18     Good
#>  4:      county03   Normal
#>  5:      county30   Normal
#>  6:      county34   Normal
#>  7:      county38  Neutral
#>  8:      county42  Neutral
#>  9:      county46  Neutral
#> 10:      county50      Bad
#> 11:      county54      Bad

# join the map data.table
pd[location_info,on="location_code",category:=category]

q <- ggplot()
q <- q + geom_polygon(
  data = pd, 
  mapping = aes(
    x = long,
    y = lat,
    group = group,
    fill=category
  ), 
  color="black", 
  size=0.25
)
q <- q + annotate(
  "text",
  x = fhimaps::norway_xxx_position_title_insert_oslo_b2020_insert_oslo_dt$long,
  y = fhimaps::norway_xxx_position_title_insert_oslo_b2020_insert_oslo_dt$lat,
  label = "Oslo"
)
q <- q + coord_quickmap()
# it is possible to use the color palette provided in fhiplot
# q <- q + fhiplot::scale_fill_fhi("Category", palette = "map_seq_complete", direction = 1)
q <- q + labs(title="")
q <- q + theme_void()
q

Add labels to each geographic unit

We can add labels of county index onto the maps. There are several options for adding texts on a graph in ggplot2. We recommend geom_label() to add the labels if no label overlap occurs, otherwise we recommend using ggrepel::geom_label_repel().

pd <- copy(fhimaps::norway_nuts3_map_b2020_insert_oslo_dt)
q <- ggplot()
q <- q + geom_polygon(
  data = pd, 
  mapping = aes(
    x = long,
    y = lat,
    group = group,
    fill = location_code
  ),  
  color="black",
  size=0.1
)
q <- q + annotate(
  "text",
  x = fhimaps::norway_xxx_position_title_insert_oslo_b2020_insert_oslo_dt$long,
  y = fhimaps::norway_xxx_position_title_insert_oslo_b2020_insert_oslo_dt$lat,
  label = "Oslo"
)
q <- q + geom_label(
  data = fhimaps::norway_nuts3_position_geolabels_b2020_default_dt,
  mapping = aes(x = long, y = lat, label = location_code)
  )
# ggrepel::geom_label_repel() for avoiding overlap
q <- q + theme_void()
q <- q + coord_quickmap()
q <- q + labs(title = "")
q

Labels can be easily added to other layouts, such as Oslo wards.

q <- ggplot(mapping = aes(x = long, y = lat))
q <- q + geom_polygon(
  data = fhimaps::oslo_ward_map_b2020_default_dt,
  mapping = aes(group = group),
  color = "black",
  fill = "white",
  size = 0.2
)
q <- q + geom_label(
  data = fhimaps::oslo_ward_position_geolabels_b2020_default_dt,
  mapping = aes(label = location_code),
  color = "red",
  size = 3,
  label.size = 0.1,
  label.r = grid::unit(0, "lines")
)
q <- q + theme_void()
q <- q + coord_quickmap()
q

enrich plot with additional data

It is convenient to use fhidata package to enrich Norway and Oslo maps with external information, such as location name and population. We illustrate how to do it here.

# enrich with population and location name
dpop_2020 <- fhidata::norway_population_b2020[
  year == '2020',
  .(pop_total = sum(pop)),
  keyby = location_code
]

# join, create label
labels <- copy(fhimaps::norway_nuts3_position_geolabels_b2020_insert_oslo_dt)
labels[
  dpop_2020, 
  on = "location_code",
  pop_total := pop_total
]
labels[
  fhidata::norway_locations_long_b2020, 
  on = "location_code",
  location_name := location_name
]
labels[, label := paste0(location_name, '\n', pop_total)]
print(head(labels))
#>    location_code  long      lat pop_total        location_name
#> 1:      county30  8.85 60.60000   1241165                Viken
#> 2:      county03 20.85 62.00000    693494                 Oslo
#> 3:      county34 11.00 61.86886    371385            Innlandet
#> 4:      county38  8.50 59.32481    419396 Vestfold og Telemark
#> 5:      county42  7.80 58.30000    307231                Agder
#> 6:      county11  6.10 58.70000    479892             Rogaland
#>                           label
#> 1:               Viken\n1241165
#> 2:                 Oslo\n693494
#> 3:            Innlandet\n371385
#> 4: Vestfold og Telemark\n419396
#> 5:                Agder\n307231
#> 6:             Rogaland\n479892

# plot
pd <- copy(fhimaps::norway_nuts3_map_b2020_insert_oslo_dt)
q <- ggplot()
q <- q + geom_polygon(
  data = pd, 
  mapping = aes(
    x = long,
    y = lat,
    group = group,
    fill = location_code
  ),
  color="black",
  size=0.1
)
q <- q + annotate(
  "text",
  x = fhimaps::norway_xxx_position_title_insert_oslo_b2020_insert_oslo_dt$long,
  y = fhimaps::norway_xxx_position_title_insert_oslo_b2020_insert_oslo_dt$lat,
  label = "Oslo"
)
q <- q + ggrepel::geom_label_repel(
  data = labels,
  mapping = aes(x = long, y = lat, label = label)
)
q <- q + theme_void()
q <- q + coord_quickmap()
q <- q + labs(title = "")
q

# enrich with population and location name
dpop_2020 <- fhidata::norway_population_b2020[
  year == '2020',
  .(pop_total = sum(pop)),
  keyby = location_code
]

# join, create label
labels <- copy(fhimaps::oslo_ward_position_geolabels_b2020_default_dt)
labels[
  dpop_2020, 
  on = "location_code",
  pop_total := pop_total
]
labels[
  fhidata::norway_locations_long_b2020, 
  on = "location_code",
  location_name := location_name
]
labels[, label := paste0(location_name, '\n', pop_total)]
print(head(labels))
#>     location_code     long      lat pop_total  location_name
#> 1: wardoslo030101 10.79760 59.91010     58671     Gamle Oslo
#> 2: wardoslo030102 10.78000 59.92567     62423    Grünerløkka
#> 3: wardoslo030103 10.76683 59.93981     45089         Sagene
#> 4: wardoslo030104 10.73555 59.91230     38945 St. Hanshaugen
#> 5: wardoslo030105 10.66500 59.89925     59269        Frogner
#> 6: wardoslo030106 10.65000 59.92500     34569         Ullern
#>                    label
#> 1:     Gamle Oslo\n58671
#> 2:    Grünerløkka\n62423
#> 3:         Sagene\n45089
#> 4: St. Hanshaugen\n38945
#> 5:        Frogner\n59269
#> 6:         Ullern\n34569

q <- ggplot(mapping = aes(x = long, y = lat))
q <- q + geom_polygon(
  data = fhimaps::oslo_ward_map_b2020_default_dt,
  mapping = aes(group = group),
  color = "black",
  fill = "white",
  size = 0.2
)
q <- q + geom_label(
  data = labels,
  mapping = aes(label = label),
  color = "red",
  size = 3,
  label.size = 0.1,
  label.r = grid::unit(0, "lines")
)
q <- q + theme_void()
q <- q + coord_quickmap()
q

sf for interactive maps

We provide the option of how to use sf class object to create interactive maps. It requres the leaflet package.

pd_county <- fhimaps::norway_nuts3_map_b2019_default_sf
leaflet::leaflet(
  pd_county,
  options = leaflet::leafletOptions(preferCanvas = F)
) %>% 
  leaflet::addProviderTiles(leaflet::providers$Esri.WorldGrayCanvas) %>%
  leaflet::addPolygons(
   #  fillColor = ~ pal_not_censored(n_0_13_fixed_status_with_numbers),
    weight = 0.3,
    opacity = 1,
    color = "black", fillColor = 'white',
    fillOpacity = 0.9  )