Get access to all lessons in this course.
Mapping with R
- Welcome to Mapping with R (01_01)
- Making Maps is Complex (01_02)
- mapview for Quick Maps (01_03)
- sf for Simple Features (01_04)
- Turning Data Frames into sf Objects (01_05)
- Importing Shapefiles (01_06)
- Joining Geospatial Datasets (01_07)
- Disambiguating Country Names (01_08)
- Converting Addresses to Coordinates (01_09)
- U.S.-Specific Datasets (01_10)
- Advice on Finding International Datasets (01_11)
- CRS and Projections: Geographic and Projected CRS (01_12)
- CRS and Projections: How to Choose a CRS (01_13)
- Introducing Raster GIS with raster and stars (01_14)
- Basics of Using the raster Package (01_15)
- ggplot2 Essentials (02_01)
- Starting a Map in ggplot2 (02_02)
- Labelling ggplot2 Maps (02_03)
- Compare Locations/Events with Geobubble Charts (02_04)
- Highlight a Region in a Country with ggplot2 (02_05)
- Make a Choropleth Map of Discrete Variables with ggplot2 (02_06)
- Make a Choropleth Map of Continuous Variables with ggplot2 (02_07)
- Faceting Choropleth Maps with ggplot2 (02_08)
- Visualize Raster Data with ggplot2 (02_09)
- Adding Scale Bars and North Arrows with ggplot2 (02_10)
- What is leaflet? (03_01)
- Starting a Map in leaflet (03_02)
- Necessary HTML for Labelling leaflet Maps (03_03)
- Highlight a Region in a Country with leaflet (03_04)
- Compare Locations/Events with Geobubble Charts in leaflet (03_05)
- Make a Choropleth Map of Discrete Variables with leaflet (03_06)
- Make a Choropleth Map of Continuous Variables with leaflet (03_07)
- Visualize Raster Data with leaflet (03_08)
- You Did It!
Converting Addresses to Coordinates (01_09)
This lesson is locked
This lesson is called Converting Addresses to Coordinates (01_09), part of the Mapping with R course. This lesson is called Converting Addresses to Coordinates (01_09), part of the Mapping with R course.
Click on the transcript to go to that point in the video. Please note that transcripts are auto generated and may contain minor inaccuracies.
library(tidyverse) library(readxl) library(janitor) library(tidygeocoder) library(sf) library(mapview) international_addresses <- read_excel("data/street-addresses.xlsx", sheet = "International Addresses") %>% clean_names() international_addresses_geocoded <- international_addresses %>% geocode(street = street_address, city = city, state = region, postalcode = postal_code, country = country, method = "iq") international_addresses_geocoded %>% st_as_sf(coords = c("long", "lat"), crs = 4326) %>% mapview()
01_09 project. In the your-turn.R file:
Convert the addresses in the “International Addresses” worksheet into coordinates and visualise them.
Import the “International Addresses” worksheet
mutate(across(...))code to remove NA values
geocode()to convert the addresses into coordinates
Visualise the locations with
This video introduces two packages for forward geocoding, which I’d like to summarise again here:
ggmap uses the Google Maps Geocoding API which is extremely well regarded and considered an industry standard. However, to register for the API you must provide your credit card details to Google. As of late 2020 users are provided with $300 free credit per month, however this could change in the future. Instructions for setting up your Google Cloud Platform account can be found on the
ggmap package website.
tidygeocoder provides access to four different geocoding API via the
“census” is the default and connects to the free to use US Census Geocoder but is only useful for addresses in the US
“osm” uses the entirely free Nominatim geocoding service from OpenStreetMaps but is explicitly not suitable for commercial or bulk geocoding
“geocodio” uses the commercial geocoding service Geocodio that covers only the US and Canada. A free tier is available and you do not need to provide your billing details for this type of account.
“iq” uses the international commercial geocoding service LocationIQ. A free tier is available and you do not need to provide your billing details for this type of account.
It’s important to remember that there is (unfortunately) not an international standard for formatting street addresses. In general, the more specific a query the more likely an API will return an accurate set of coordinates.