5-minute map

[This article was first published on r.iresmi.net, 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.

A photo of a clock

Clock 10:05 – CC-BY-NC-ND by Bill Dickinson

Day 19 of 30DayMapChallenge: « 5-minute map » (previously).

Setup

library(tidyverse)
library(leaflet)
library(httr)
library(fs)
library(glue)

Data

We reuse the Geonames data from Bad map.

gn_file <- "~/data/geonames/allCountries.zip"

if (!file_exists(gn_file)) {
  GET("http://download.geonames.org/export/dump/allCountries.zip",
      write_disk(gn_file))
}

gn <- read_delim(
  gn_file, 
  delim = "\t", 
  col_names = c("geonameid",     
                "name",          
                "asciiname",     
                "alternatenames",
                "latitude",      
                "longitude",     
                "feature_class", 
                "feature_code",  
                "country_code",  
                "cc2",           
                "admin1_code",   
                "admin2_code",   
                "admin3_code",   
                "admin4_code",   
                "population",    
                "elevation",     
                "dem",           
                "timezone",      
                "modification_date"))

We randomly keep five places containing “minute”…

set.seed(314)

minute <- gn |> 
  filter(str_detect(asciiname, "\\b[Mm]inute\\b")) |> 
  slice_sample(n = 5)

Map

minute |> 
  leaflet() |> 
  addCircleMarkers(popup = ~ glue("{name} ({asciiname})<br />
                                  <b>{country_code}</b>"),
                   label = ~ asciiname,
                   labelOptions = labelOptions(noHide = TRUE)) |> 
  addTiles(attribution = "Geonames and © OpenStreetMap, ODbL")
Figure 1: … and here is the Five minute map
To leave a comment for the author, please follow the link and comment on their blog: r.iresmi.net.

R-bloggers.com 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)