The following page was copied from a knitted (html) R Markdown document, available at my github page.
ICAO traffic
2023-07-05
R Markdown
This dataset and resulting visualisation is simple, the objective was to demonstrate extracting information from a PDF table and creating a simple hybrid chart in R using ggplot2 library. The resulting dataset — ICAO World total revenue traffic international and domestic (scheduled services of airlines of ICAO Contracting States) – shows the evolution of the global traffic over past few years (with separate data for passenger and cargo traffic).
The first phase (data preparation) is described in this article.
icao_revenue <- read.csv("D:/world_total_revenue_traffic_CLEANED.csv")
####This is the code I wrote in R (Rstudio) for the hybrid chart:
head(icao_revenue)
## Year X.Pax_ann_millions. X.Pax_ann_inc_perc..... Km_pax_ann_millions
## 1 1998 1471 1.0 2628120
## 2 1999 1562 6.2 2797800
## 3 2000 1672 7.0 3037530
## 4 2001 1640 -1.9 2949550
## 5 2002 1639 -0.1 2964530
## 6 2003 1691 3.2 3019100
## Km_pax_ann_inc_perc Freight_tonnes_mill Freight_tonnes_inc_perc
## 1 2.1 27 0.4
## 2 6.5 28 6.0
## 3 8.6 30 8.2
## 4 -2.9 29 -5.3
## 5 0.5 31 9.0
## 6 1.8 34 6.7
## Km_freight_tonne Km_freight_tonne_inc_perc
## 1 101820 -1.0
## 2 108660 6.7
## 3 118080 8.7
## 4 110800 -6.2
## 5 119840 8.2
## 6 125760 4.9
scaling_factor <- max(icao_revenue$Km_pax_ann_millions) / max(icao_revenue$Km_freight_tonne)
ggplot(data = icao_revenue) + geom_col(aes(x = Year, y=Km_pax_ann_millions), fill="cyan") + labs(title= "Total scheduled traffic (1998-2021)",
x="Year",y="Passenger-kilometres (Billions)") +
geom_line(aes(x=Year, y=Km_freight_tonne * scaling_factor), color="red", linewidth=3) +
scale_y_continuous(sec.axis = sec_axis(~ . / scaling_factor, name = "Freight tonne-kilometres performed (Billions)"))
Note the difference in impact of the COVID-19 crisis in 2019 for the passenger and freight (cargo traffic).