This document presents an interactive map created with leaflet that highlights the location of three major Wall Street companies, drawing a triangle that connects their positions. Additionally, various leaflet tools are incorporated to enhance the interactive experience.
library(leaflet)
library(dplyr)
library(leaflet.extras)
We define a data frame with the names and approximate coordinates of the three major Wall Street financial firms.
# Data frame with companies and their approximate coordinates
companies <- data.frame(
company = c("Goldman Sachs", "Morgan Stanley", "JP Morgan Chase"),
lat = c(40.7069, 40.7580, 40.730610),
lng = c(-74.0113, -73.9787, -73.935242)
)
To visualize the triangle connecting the companies, we create a new data frame containing their coordinates. The first point is repeated at the end to close the polygon.
# Data frame to draw the triangle by connecting company locations
triangle <- data.frame(
lat = c(companies$lat, companies$lat[1]),
lng = c(companies$lng, companies$lng[1])
)
We define a custom marker icon using FontAwesome to visually represent the company locations
# Custom icon for financial companies using FontAwesome
companyIcon <- awesomeIcons(
icon = 'building',
markerColor = 'blue',
iconColor = 'white',
library = 'fa'
)
Now, we create the interactive map, adding base layers, company markers, and the triangle connecting them.
m <- leaflet(width = "100%") %>%
# Base maps
addTiles(group = "OSM") %>%
addProviderTiles(providers$CartoDB.Positron, group = "CartoDB") %>%
# Markers for the companies
addAwesomeMarkers(data = companies, lat = ~lat, lng = ~lng,
popup = ~company, icon = companyIcon,
group = "Companies") %>%
# Drawing the triangle connecting the companies
addPolylines(data = triangle, lat = ~lat, lng = ~lng,
color = "red", weight = 3, opacity = 0.8,
popup = "Wall Street Triangle",
group = "Triangle") %>%
# Layer control panel
addLayersControl(
baseGroups = c("OSM", "CartoDB"),
overlayGroups = c("Companies", "Triangle"),
options = layersControlOptions(collapsed = FALSE)
) %>%
# Adding a scale bar
addScaleBar(position = "bottomleft") %>%
# Mini map for better navigation
addMiniMap(toggleDisplay = TRUE, position = "bottomright") %>%
# Fullscreen control button
addFullscreenControl() %>%
# Measurement tool for distances and areas
addMeasure(
position = "topleft",
primaryLengthUnit = "meters",
primaryAreaUnit = "sqmeters",
activeColor = "#3D535D",
completedColor = "#7D4479"
)
# Display the interactive map
m