This week’s challenge is to play around with some other aspects of visualization.
I have created my own dataset to map, which is just the beginning of a larger project to create a map of the food system of Missoula, MT. The map will ultimately include all food systems entities and US Census Data and be used to analyze our food system through multiple lenses.
Since I am creating the dataset myself, this will be a great opportunity to practice good data governance. This will allow me to minimize cleaning when it comes time to analyze the data.
# set working directory
setwd("~/Documents/R Projects/Data")
# read data
foodSystem <- read_excel("Missoula Food System.xlsx")
foodSystemDF <- as.data.frame(foodSystem)
foodSystemDF
## Category Name Neighborhood Ward
## 1 grocery store Good Food Store River Road 6
## 2 grocery store Orange Street Food Farm Riverfront 3
## 3 grocery store Albertsons Heart of Missoula 1
## 4 grocery store Missoula Fresh Market <NA> NA
## 5 grocery store Natural Grocers <NA> NA
## 6 grocery store Albertson's <NA> NA
## 7 grocery store Pattee Creek Market <NA> NA
## 8 grocery store Albertsons <NA> NA
## 9 grocery store Missoula Fresh Market <NA> NA
## 10 grocery store WinCo <NA> NA
## 11 grocery store Roasauers <NA> NA
## 12 grocery store Albertsons <NA> NA
## Address Duration
## 1 1600 S 3rd St W, Missoula, MT 59801 year-round
## 2 701 S Orange St, Missoula, MT 59801 year-round
## 3 1003 E Broadway St, Missoula, MT 59802 year-round
## 4 800 W Broadway St, Missoula, MT 59802 year-round
## 5 2530 S 3rd St W, Missoula, MT 59804 year-round
## 6 2230 N Reserve St, Missoula, MT 59808 year-round
## 7 704 SW Higgins Ave, Missoula, MT 59803 year-round
## 8 3800 S Russell St, Missoula, MT 59801 year-round
## 9 3801 S Reserve St, Missoula, MT 59801 year-round
## 10 2510 S Reserve St, Missoula, MT 59801 year-round
## 11 2350 S Reserve St, Missoula, MT 59801 year-round
## 12 2205 Oxford St, Missoula, MT 59801 year-round
There are some missing values but other than that this dataset is nice and tidy. I am in the first stage of data collection but playing around with the data now will give me a chance to assess my collection methods and data structure while it’s still easy to change course.
Category will eventually include any physical location where one can acquire food (grocery store, farmers market, food bank, CSA pickup location, etc.) as well as other features relevant to the food system (e.g. public transportation).
Name refers to the name of the entity.
Neighborhood and Ward refer to specific boundaries within the city.
Address is the street address of the entity. While I will ultimately use latitude and longitude to map these locales, I’ll be collecting the street address for the dataset. This is partially because Google Maps provides a handy Copy address feature, making it the easiest, least-error-prone option, and partially because a street address is more relevant to the end-user than latitude and longitude.
Duration refers to the duration of time that feature is available. As of right now the values for this variable include year-round and seasonal. Other possible values may reveal themselves as I continue to collect data (e.g. holiday).
The background map for this project will need to include the boundaries for the City of Missoula and Missoula County, as well as the neighborhood boundaries.
# get lat and long using ggmap
foodSystem <- mutate_geocode(foodSystem, Location)
It looks like Google Maps now requires an API key to use its geocoding service so I won’t be able to utilize the ggmap package until I register for an API key. Instead of sorting that out now right now, I’m going to try the tidygeocoder package, which uses the geocoding service Nominatim.
# get lat and long using tidygeocoder
foodSystemDF <- foodSystemDF %>%
geocode(Address, method = 'osm', lat = Latitude, long = Longitude)
foodSystemDF
## # A tibble: 12 × 8
## Category Name Neighborhood Ward Address Duration Latitude Longitude
## <chr> <chr> <chr> <dbl> <chr> <chr> <dbl> <dbl>
## 1 grocery store Good … River Road 6 1600 S … year-ro… 46.9 -114.
## 2 grocery store Orang… Riverfront 3 701 S O… year-ro… 46.9 -114.
## 3 grocery store Alber… Heart of Mis… 1 1003 E … year-ro… 46.9 -114.
## 4 grocery store Misso… <NA> NA 800 W B… year-ro… 46.9 -114.
## 5 grocery store Natur… <NA> NA 2530 S … year-ro… 46.9 -114.
## 6 grocery store Alber… <NA> NA 2230 N … year-ro… 46.9 -114.
## 7 grocery store Patte… <NA> NA 704 SW … year-ro… 46.8 -114.
## 8 grocery store Alber… <NA> NA 3800 S … year-ro… 46.8 -114.
## 9 grocery store Misso… <NA> NA 3801 S … year-ro… 46.9 -114.
## 10 grocery store WinCo <NA> NA 2510 S … year-ro… 46.8 -114.
## 11 grocery store Roasa… <NA> NA 2350 S … year-ro… 46.8 -114.
## 12 grocery store Alber… <NA> NA 2205 Ox… year-ro… 46.9 -114.
save(foodSystemDF, file="~/Documents/R Projects/Data/foodSystemDF")
Now that I have geocoded the addresses, I am going to create a simple map. For this I’ll use the leaflet package.
# load leaflet library
library(leaflet)
# create map and assign to object foodSystemMap
foodSystemMap <- leaflet(foodSystemDF) %>%
addTiles() %>%
addMarkers(popup = ~as.character(Name), label = ~as.character(Name))
foodSystemMap
Okay! Pretty basic but it’s a start. Eventually I’ll want to draw the relevant boundaries (City of Missoula, Missoula County, neighborhoods, Wards), as well as have different icons for different categories of entities. Using US Census data I’ll be able to compare areas across a variety a metrics and, importantly, analyze if/how those metrics relate to the food system.