Learn Danish geography with leaflet

This page draws a map showing the placement of major Danish cities. Population is shown through the area of circles around each city. The app is made using the Leaflet library for R.

Load Leaflet library

library(leaflet)

List of cities

A list of the 20 largest Danish cities:

cities <- data.frame(longitude = c(12.5689, 10.2, 10.3833, 9.9194, 8.4514, 10.0392, 9.4667,
                                   9.8519, 9.5333, 12.0808, 8.9667, 12.4992, 12.6067,
                                   9.55, 11.7567, 9.75, 9.4, 12.1797, 8.6167, 12.3),
                     latitude = c(55.6772, 56.15, 55.4, 57.0511, 55.4708, 56.4569, 55.4833,
                                  55.8619, 55.7014, 55.6417, 56.1333, 55.8786, 56.035,
                                  56.1667, 55.2294, 55.5667, 56.45, 55.4561, 56.3667, 55.65),
                     pop = c(1280371, 264716, 175245, 112194, 72151, 62342, 59712,
                             57517, 54862, 50046, 48531, 47000, 46829,
                             43885, 42979, 40248, 39856, 36831, 35392, 33971))

Make flag

A nice Danish flag icon:

flag <- makeIcon(iconUrl = "flag.png",
                 iconWidth = 50, iconHeight = 50,
                 iconAnchorX = 17, iconAnchorY = 47)

Create map

Finally, the map itself:

map <- cities %>%
  leaflet() %>%
  addTiles() %>%
  addMarkers(icon = flag,
             clusterOptions = markerClusterOptions(),
             popup = c("Copenhagen", "Aarhus", "Odense", "Aalborg", "Esbjerg", "Randers", "Kolding",
                       "Kolding", "Vejle", "Roskilde", "Herning", "Hørsholm", "Elsinore",
                       "Silkeborg", "Næstved", "Fredericia", "Viborg", "Køge", "Holstebro", "Taastrup")) %>%
  addCircles(weight = 2, radius = sqrt(cities$pop) * 25)
map