Synopsis

This HTML document is created from the associated R Markdown file. In this assignment, I have organized data in various tibbles, turning them into more userful form using functions of tidyverse package. I have also done operations on relational data to perform analysis on more than one tables at one time.

Packages Required

    library(ggplot2)  #Package to produce complex multi-layered graphs in R
    library(tidyverse) #Set of packages including dpylr and ggplot

Source Code

The markdown is based on seven data sets that contains information about United States Air Force bomber aircrafts. Following variables are parts of these data sets:

  1. Type: Represents the type of Bomber aircrafts

  2. MD: Combination of basic mission of the aircraft and the design number

  3. FY: Fiscal year from 1996-2014

  4. Cost: Represents the total operational cost for flying, maintaining, repairing, and managing the aircraft

  5. FH: Represents the flying hours, which is the total time the aircraft is in the air flying a mission or in training

  6. Gallons: Represents the total gallons of fuel burned by the aircraft

Note: The data sets contains no missing values or empty rows.

Data Analysis

Question 1

bomber_wide<-read_rds("bomber_wide.rds")
bomber_wide<-as_tibble(bomber_wide)

bomber_wide%>%
    gather( key="Year", value="FH", c(-(Type:MD)))

Question 2

bomber_long<-read_rds("bomber_long.rds")
bomber_long<-as_tibble(bomber_long)

bomber_long%>%
    spread(key="Output", value="Value")

Question 3

bomber_combined<-read_rds("bomber_combined.rds")
bomber_combined<-as_tibble(bomber_combined)

bomber_combined%>%
    separate(AC, into = c("Type", "MD"), sep=" ")

Question 4

bomber_prefix<-read_rds("bomber_prefix.rds")
bomber_prefix<-as_tibble(bomber_prefix)

bomber_prefix%>%
    unite(MD, prefix,number,sep="-")%>%
    spread(key="Output", value="Value")

Question 5

bomber_mess<-read_rds("bomber_mess.rds")
bomber_mess<-as_tibble(bomber_mess)

bomber_mess%>%
    unite(MD, prefix,number,sep="-")%>%
    separate(Metric, into=c("FY", "Output"))%>%
    spread(key="Output", value="Value")

Question 5 Plot

bomber_mess %>%
    unite(MD,prefix,number,sep="-") %>%
    separate(Metric,into = c("FY","Output"),sep="_")%>%
    ggplot(aes(x=FY, y=Value,group=MD, colour = MD)) + 
    geom_line() + geom_point() + facet_grid(Output~., scales = "free") +
    ggtitle("Mission Design Aircrafts Metrics") +
    labs(y="Value", x="Year")+
    theme(axis.text=element_text(size=6),
        axis.title=element_text(size=6))

Question 6

ws_programmatics <- as_tibble(read_rds("ws_programmatics.rds"))
ws_categorization <- as_tibble(read_rds("ws_categorizations.rds"))

ws_programmatics %>% 
    left_join(ws_categorization,by=c("Base","MD")) %>%
    filter(FY == 2014  & Base == "MINOT AFB (ND)") %>%
    filter(System=="AIRCRAFT" | System=="MISSILES") %>%
    group_by(System) %>%
    summarise(Total_Sum = sum(Total_O.S,na.rm=TRUE),Total_end_Strength = sum(End_Strength,na.rm=TRUE))

Question 7

ws_programmatics %>% 
    left_join(ws_categorization,by=c("Base","MD")) %>%
    filter(FY == 2014) %>%
    group_by(Base) %>%
    summarise(CPFH = sum(Total_O.S,na.rm=TRUE)/sum(FH,na.rm=TRUE))%>%
    filter(CPFH != Inf) %>%
    arrange(desc(CPFH)) %>%
    head(n=10) %>%
    select(Base,CPFH)%>%
    ggplot() +
    geom_bar(mapping = aes(x = reorder(Base,CPFH),y=CPFH),stat="Identity") +
    coord_flip() +
    ggtitle(" Top 10 bases with the highest cost per flying hours") +
    labs(y="Cost/Flying Hours", x="Bases")

Question 8

ws_programmatics %>% 
    left_join(ws_categorization,by=c("Base","MD")) %>%
    gather("Output","Value",c(FY,System,FH)) %>%
      group_by(Output) %>%
        ggplot(mapping=aes(x=End_Strength,y=Total_O.S, color=Output)) +
          geom_point() + facet_grid(~Output)