Not too long ago, I came across a random tweet pointing to a GitHub repository full of miscallaneous datasets. I was imemdiately excited by the various data science and visualization problems tha I could take on and immediately decided to get my hands dirty. One of the first datasets that I saw was a dataset called
eleavtors. As stated on the github repo, it contains
A list of registered elevator devices in New York City provided by the Department of Buildings in response to a September 2015 FOIL request. The data was received on a DVD in November 2015. The spreadsheet contains information on 76,088 elevators in New York City.
As a resident of NYC, and someone who has mayny times complained abut going to friends houses with no elevators (admittedly a first-world problem…), I wanted to take a look at that data. (Full disclosure, half-way through this little project, I realized that fivethirtyeight had already beaten me to the punch and performed an analysis of its own.
A map of elevators in NYC
The main point of this post is to illustrate how simple it is to produce interactive leaflet map using the
htmlwidgets package in
R. in fact, it is only a single line of code to produce the map above, the rest is just processing the data into the correct format. A word of advice when using the
leaflet package at the zipcode level: the library expects 5 digits for all US-based zipcode, while many databases produce zipcodes that sometimes contain 4 digits. If that happens, it is necessary to pad “0”s to the zipcode until the string in question has a length of five. This can be achieved using a neat little trick that is shown in line 11 of the code below!