Lunch Spots Around the New York Genome Center

Heather Geiger

December 27, 2017

Load libraries.

library(leaflet)
library(dplyr)
## 
## Attaching package: 'dplyr'
## The following objects are masked from 'package:stats':
## 
##     filter, lag
## The following objects are masked from 'package:base':
## 
##     intersect, setdiff, setequal, union

Set up data frame with locations of the restaurants plus their name and cost.

lunch_spots <- data.frame(Name = c("Sunrise Mart","David Burke Kitchen","Pi Bakerie","Aurora Soho","Soho's Finest Market"),
lat = c(40.7205332,40.7228421,40.7236727,40.7235394,40.722717),
lng = c(-74.0047563,-74.0070633,-74.0055194,-74.005364,-74.0067467),
Cost = c("$","$$$","$$","$$$","$"),stringsAsFactors=FALSE)

#Reorder by ease of walking to them from the New York Genome Center.

lunch_spots <- lunch_spots[c(2,5,3,4,1),]

Map the cost of the restaurants to a set of colors. Lighter shade of blue = cheaper.

cost_colors <- plyr::mapvalues(x = lunch_spots$Cost,from = c("$","$$","$$$"),to=c("lightblue","blue","darkblue"))

Set up an icon with the New York Genome Center logo.

I already downloaded it to my computer, so I reference the path to it on my system.

I downloaded this file here: https://pbs.twimg.com/profile_images/876793647429275648/tISDuxCu_400x400.jpg

NYGC_icon <- makeIcon(iconUrl = "/Users/hmgeiger/Downloads/logo2.jpg",
iconWidth = 50,iconHeight = 50,iconAnchorX = 25,iconAnchorY = 25)

Make map.

#addLegend displays different colors for the same text value than makeAwesomeIcon. So, we use the hex values of these colors created by makeAwesomeIcon for the legend.
my_map <- lunch_spots %>% leaflet %>% addTiles() %>% addAwesomeMarkers(popup=lunch_spots$Name,icon=makeAwesomeIcon(markerColor = cost_colors,iconColor="white",text =1:nrow(lunch_spots))) %>% addLegend(label = c("$","$$","$$$"),colors = c("#94D3F4","#54A6D4","#23659B"))
## Assuming 'lng' and 'lat' are longitude and latitude, respectively
my_map <- my_map %>% addMarkers(popup = "New York Genome Center",lat = 40.7234434,lng = -74.0073053,icon=NYGC_icon)
my_map