# Bangladesh International Flight Network This R project visualizes the international flight routes from Bangladesh using OpenFlights data and shapefiles for geographic context. ## π Useful Links - [Go to Live Interaction Map](bdflight.netlify.app) - [Full R Code](https://github.com/iu-parvej/Bangladesh-Flight-Network/blob/main/Interactive_version_bangladesh_flight_network.R) ## πFeatures - Visualizes international routes departing from Bangladeshi airports - Spatial network representation using `ggraph` and `sf` - Interactive labeling and customized layout - Aesthetic dark-themed output image # How to Build an Interactive Bangladesh Flight Network Map with Embedded Flight Radar ### 1οΈβ£ Set Up Your Environment Install R and RStudio (if not already installed). Install required packages using the following command: ```r install.packages(c("tidyverse", "sf", "leaflet", "htmltools", "htmlwidgets", "viridis", "geosphere")) ``` ### 2οΈβ£ Prepare Your Data - **Download** the shapefile for Bangladesh's administrative boundaries. - **Obtain** airport and route data (e.g., from OpenFlights: `airports.dat`, `routes.dat`). - **Read** the shapefile using: ```r sf::st_read("path/to/shapefile") ``` - **Load** airports and routes as CSVs: ```r read.csv("airports.csv") read.csv("routes.csv") ``` ### 3οΈβ£ Filter and Clean Data - **Filter airports** to only include Bangladesh (`Country == "Bangladesh"`). - **Select** international routes departing from BD airports to destinations outside BD (no stops). - **Join** airport data with routes for coordinates. ### 4οΈβ£ Create Curved Flight Lines - Use `geosphere::gcIntermediate()` to create smooth curved paths: ```r geosphere::gcIntermediate(c(lon1, lat1), c(lon2, lat2), n=50, addStartEnd=TRUE) ``` - Convert paths to spatial lines: ```r sf::st_linestring(matrix(c(lon1, lat1, lon2, lat2), ncol=2)) ``` ### 5οΈβ£ Build Your Leaflet Map - Initialize **Leaflet** with a preferred base map (e.g., *CartoDB.DarkMatter* or *Esri.WorldImagery*). - Add **Bangladesh polygon** shapefile with a semi-transparent fill. - Overlay **curved flight paths** with color-coded origins, dashed styles, and interactive popups. - Add **airport markers** with hover tooltips. ### 6οΈβ£ Add Interactivity Enhance user interaction with **JavaScript event handlers**: ```js htmlwidgets::onRender(" function(el,x) { el.on('mouseover', function() { this.style.stroke = 'blue'; this.style.strokeWidth = '2'; }); } ") ``` - Utilize `labelOptions(sticky = TRUE)` to prevent flickering hover labels. ### 7οΈβ£ Add Title & Legend - Add a **bold title** at the top center: ```r leaflet::addControl("