This project includes creating a web page using R Markdown that features a map created with Leaflet. The webpage is hosted on RPubs. The map for this project is that of four airports in the Phoenix, Arizona area. The locations of the airports are identified with an airplane icon and can be clicked to identify the name of the airport.
library(leaflet)
## Warning: package 'leaflet' was built under R version 4.3.3
Note the latitude and longitude data of the airports was derived from Google maps.
airport_name <- c("Phoenix Deer Valley","Phoenix-Goodyear","Phoenix-Mesa Gateway Airport","Phoenix Sky Harbor Airport")
airport_lat <- c(33.769350860734974,33.4552683531278,33.356810684784634,33.46694236368442)
airport_lng <- c(-112.07131161018536,-112.37668640459187,-111.66702881471394,-112.00686485072457)
airport_df <- data.frame(name =airport_name,lat=airport_lat,lng=airport_lng)
print(airport_df)
## name lat lng
## 1 Phoenix Deer Valley 33.76935 -112.0713
## 2 Phoenix-Goodyear 33.45527 -112.3767
## 3 Phoenix-Mesa Gateway Airport 33.35681 -111.6670
## 4 Phoenix Sky Harbor Airport 33.46694 -112.0069
airportIcon <- makeIcon(
iconUrl = "airplane.png",
iconWidth = 31*215/230, iconHeight = 31,
iconAnchorX = 31*215/230/2, iconAnchorY = 16
)
airport_map <- leaflet() %>%
addTiles()
for(i in 1:nrow(airport_df)) {
airport_map <- airport_map %>%
addMarkers(icon = airportIcon,
lng = airport_df$lng[i],
lat = airport_df$lat[i],
popup = airport_df$name[i]
)
}
airport_map
Click on the airplane icon to identify the airport location.