I make a lot of maps, almost always in R. Recently, I was introduced to felt.com. It’s a clean interface for web maps, including some great features, like drawing directly on a map or adding text annotations.
The new feltr package offers an interface to the Felt API, so you can upload data to Felt directly from R. It also includes tools for reading data from Felt into R as sf objects.
Below, I’ll demo making a map with point locations of Dunkins in Cambridge, MA, from a csv file of Dunkin addresses.
Dunkins in Cambridge, MA
First, we’ll load a few packages.
library(feltr)library(tidyverse)
── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
✔ dplyr 1.1.2 ✔ readr 2.1.4
✔ forcats 1.0.0 ✔ stringr 1.5.0
✔ ggplot2 3.4.2 ✔ tibble 3.2.1
✔ lubridate 1.9.2 ✔ tidyr 1.3.0
✔ purrr 1.0.1
── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
✖ dplyr::filter() masks stats::filter()
✖ dplyr::lag() masks stats::lag()
ℹ Use the conflicted package (<http://conflicted.r-lib.org/>) to force all conflicts to become errors
library(here)
here() starts at /Users/chris/Documents/GitHub/christopherkenny.github.io
One of the cool things with Felt is its “Upload Anything” feature, where we can upload anything. Here, we have a csv file of addresses for every Dunkin in Cambridge. It is simple, just text addresses separated into appropriate fields.
# A tibble: 1,062 × 5
address city state zipcode id
<chr> <chr> <chr> <chr> <dbl>
1 147 N Quincy St Abington MA 02351 1
2 259 Brockton Ave Abington MA 02351 2
3 323 Centre Ave Abington MA 02351 3
4 937 Bedford St Abington MA 02351 4
5 100 Powdermill Rd Acton MA 01720 5
6 182 Great Rd Acton MA 01720 6
7 212 Main St Acton MA 01720 7
8 315 Main St Acton MA 01720 8
9 44 Great Rd Acton MA 01720 9
10 150 S Main St Acushnet MA 02743 10
# ℹ 1,052 more rows
To share this data with Felt, we first have to make a new map. We don’t have to give it any information, it’ll just make an empty map. We can pass it a title and some starting information, like where to center the map and how far to zoom.
Then once we have the map, we can upload the csv file directly to Felt. No local geocoding necessary, it’ll handle that. We can label the layer with name or supply colors, like fill_color and stroke_color.
Once we do that, after a couple of minutes, we have a map. Normally it’s a few seconds if we uploaded a geojson or shp file, but geocoding takes a small bit of time.
What I find great about this is that I can handle all of the data work in R and then adjust the map as needed after. For example, I can annotate where the Department of Government buildings are with a green star or highlight where Darwin’s was (until recently) with a blue x.
Clearly, Darwin’s old location would be a great place for a new Dunkin, near the middle of an existing Dunkin desert.
feltr has additional features, including:
deleting maps with felt_delete_map()
listing details of existing maps with felt_get_map() and felt_get_map_layers()
downloading shapes with felt_get_map_sf(), felt_get_map_geojson(), and felt_get_map_elements()
retrieving user details with felt_get_user().
All current features of the Felt API are supported in the CRAN version of feltr, as of July 2023. To offer feedback on feltr or ask questions, open an issue on GitHub.
Citation
BibTeX citation:
@online{t._kenny2023,
author = {T. Kenny, Christopher},
title = {Making {Maps} with `Feltr`},
date = {2023-07-07},
url = {https://christophertkenny.com/posts/2023-07-07-making-maps-with-feltr/},
langid = {en}
}