This Markdown document aims to show on a map the first 8 Listed US Companies by Market Cap on an US Map; We will start by importing the libraries needed:
library(leaflet)
Then we create a dataframe, to hold the data we want to show on the map (see comments for details)
Company <- c('Microsoft','Apple','Amazon','Alphabet','Berkshire Hathaway','Facebook','Johnson & Johnson','Exxon Mobil') #Companies
MarketCap <- c(904.86, 895.67, 874.71,818.16,493.75,475.73,372.23,342.17) #Market Cap
lat <- c(47.6493198, 37.3229978, 47.608013,37.386051,41.257160,37.452961,40.4862158, 32.819595) #Latitude of HQ
lng <- c(-122.121513, -122.0321823, -122.335167,-122.083855, -95.995102,-122.181725,-74.4518188, -96.945419) #Longitude of HQ
df <- data.frame(Company, MarketCap,lat,lng)
Here the map is being created:
map <- df %>%
leaflet() %>%
addTiles() %>%
setView(lat = 39.742043, lng=-104.991531, zoom = 4) %>%
addCircleMarkers(df$lng, df$lat, radius = df$MarketCap/100, popup=paste("Company:", df$Company, "<br>",
"Market Cap:", df$MarketCap))
map