Professional Documents
Culture Documents
2018
2018/08/13
1. Introduction
This analysis is purely created for non commercial use only. The purpose of this analysis is to inform the reader about the traffic of air
plane by the time of the year, so that the reader can take advantage to plan their vacation or business trip wisely.
2. Research Question
3. Preparation
In [1]:
library(data.table)
library(plotly)
library(stringr)
library(tibble)
library(dplyr)
library(readr)
library(ggplot2)
library(tidyr)
library(xml2)
head(airport)
last_plot
filter
layout
layout
filter, lag
City1 City2 Month Passenger_Trips Aircraft_Trips Passenger_Load_Factor Distance_GC_(km) RPKs ASKs Seats
Albury Sydney 38353 9569 362 70.6 452 4325188 6128668 13559
Albury Sydney 38384 10416 398 69.6 452 4708032 6764632 14966
Albury Sydney 38412 12371 444 67.0 452 5591692 8347536 18468
Albury Sydney 38443 11939 434 65.9 452 5396428 8185268 18109
Albury Sydney 38473 11876 455 66.7 452 5367952 8041984 17792
Albury Sydney 38504 11184 442 61.2 452 5055168 8265272 18286
In [2]:
#Load city data
head(city.australia)
In [3]:
str(airport)
The most granular data of the airport data set is the summary of flight each month between two Australian cities.
6. Data Wrangling
In [4]:
airport <- merge(airport,city.australia,by.x = 'City1',by.y = 'City')
names(airport)[13] <- 'City1.Latitude'
names(airport)[14] <- 'City1.Longitude'
head(airport)
City2 City1 Month Passenger_Trips Aircraft_Trips Passenger_Load_Factor Distance_GC_(km) RPKs ASKs Seats
Alice
Adelaide 40483 0 0 0.0 1316 0 0 0
Springs
Alice
Adelaide 40452 0 0 0.0 1316 0 0 0
Springs
Alice
Adelaide 41671 0 0 0.0 1316 0 0 0
Springs
Adelaide 41671 0 0 0.0 1316 0 0 0
Springs
City2 City1 Month Passenger_Trips Aircraft_Trips Passenger_Load_Factor Distance_GC_(km) RPKs ASKs Seats
Alice
Adelaide 40391 0 0 0.0 1316 0 0 0
Springs
Alice
Adelaide 40330 0 0 0.0 1316 0 0 0
Springs
Alice
Adelaide 42156 9846 94 67.5 1316 12957336 19184648 14578
Springs
7. Analysis
In [5]:
airport <- airport %>% mutate(id = rownames(airport))
airport.1 <- airport %>%
select(-contains("Latitude"), -contains("Longitude"))
airport.1 <- airport.1 %>%
gather('City1', 'City2', key = "Airport.type", value = "City")
airport.1$Airport.type <- airport.1$Airport.type %>% str_replace(pattern = "City1", replacement =
"Departure")
airport.1$Airport.type <- airport.1$Airport.type %>% str_replace(pattern = "City2", replacement =
"Arrive")
airport.1 <- merge(airport.1, city.australia, by.x = "City", by.y = "City")
head(airport.1)
City Month Passenger_Trips Aircraft_Trips Passenger_Load_Factor Distance_GC_(km) RPKs ASKs Seats Year
In [6]:
au.map <- map_data('world') %>% filter(region == "Australia") %>% fortify()
head(au.map)
In [23]:
In [23]:
map_aus_plot
Warning message:
"Ignoring unknown aesthetics: x, y"
In [14]:
plot.year <- airport.1 %>%
ggplot(aes(x = Year, fill = City)) +
ggplot(aes(x = Year, fill = City)) +
geom_bar() +
labs(title = "Airport Traffic Amount by City from 2005 to 2018")
ggplotly(plot.year)
In [9]:
ls()
In [30]:
In [32]:
Warning message:
"Ignoring unknown aesthetics: x, y"
In [35]:
ggplotly(map_aus_plot)
Error in mutate_impl(.data, dots): Column `id` can't be modified because it's a grouping variable
Traceback:
1. ggplotly(map_aus_plot)
2. ggplotly.ggplot(map_aus_plot)
3. gg2list(p, width = width, height = height, tooltip = tooltip,
. dynamicTicks = dynamicTicks, layerData = layerData, originalData = originalData,
. source = source, ...)
4. Map(function(x, y) {
. if (is.null(y[["group"]]))
. return(x)
. dplyr::group_by_(x, y[["group"]])
. }, return_dat, mappingFormulas)
5. mapply(FUN = f, ..., SIMPLIFY = FALSE)
6. (function (x, y)
. {
. if (is.null(y[["group"]]))
. return(x)
. dplyr::group_by_(x, y[["group"]])
. })(dots[[1L]][[3L]], dots[[2L]][[3L]])
7. dplyr::group_by_(x, y[["group"]])
8. group_by_.data.frame(x, y[["group"]])
9. group_by(.data, !!!dots, add = add)
10. group_by.data.frame(.data, !!!dots, add = add)
11. group_by_prepare(.data, ..., add = add)
12. add_computed_columns(.data, new_groups)
13. mutate(.data, !!!mutate_vars)
14. mutate.tbl_df(.data, !!!mutate_vars)
15. mutate_impl(.data, dots)
In [34]:
map_aus_plot