alperyilmaz / dav-exercises

Exercise questions submitted by Data Analysis and Visualization with R course students at YTU
GNU General Public License v3.0
1 stars 2 forks source link

Data Manipulation and Data Visualization #6

Open bestepamukogullar opened 6 years ago

bestepamukogullar commented 6 years ago

Question

1- The Big Machines Journal is the most widely read journal of the 2014 year in New York. In this month's edition, you want to write about airplane companies. You want to find out which company produced the plane which made most flight in 2013.

Manufacturer Tailnum total_flight
…………….. ……………… …………..

2-Also,you want to visually reinforce your narrative. A chart which shows the total flight number with manufacturer of planes which have more than 370 flight will be fantastic! Please write a code for get this chart:

image

You can work with “nycflights13” package. ( Airline on-time data for all flights departing NYC in 2013. Also includes useful 'metadata' on airlines, airports, weather, and planes.)


HINT: **REMEMBER** in the “nycflights13” package , some of the plane have no manufacturer data. 
Do not forget to remove it.

install.packages("nycflights13")

library(nycflights13)
library(dplyr)
library(ggplot2)

# First step,

flights %>%
  left_join(planes, by="tailnum", suffix=c(".f",".p")) %>%
  group_by (manufacturer,tailnum) %>%
  summarise(total_flight= n()) %>%
  filter(!is.na(manufacturer)) %>%
  arrange(desc(total_flight)) %>%
  ungroup() %>%
  top_n(1)

# Second step,

flights %>%
    left_join(planes, by="tailnum", suffix=c(".f",".p")) %>%
    group_by (manufacturer,tailnum) %>%
    summarise(total_flight= n()) %>%
    filter(total_flight > 370, !is.na(manufacturer)) %>%
    ungroup() %>%
    mutate(tailnum= reorder(tailnum,total_flight )) %>%
    ggplot(aes(x=tailnum,y=total_flight, fill= manufacturer)) +
    geom_col(show.legend = TRUE)+
    xlab("Plane's Tailnum") +
    ylab("Total Flight Number") +
    coord_flip()

Additional information

Originality

Difficulty Level

alperyilmaz commented 6 years ago

very nice.. will process it and then add to questions file..