Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- library(tidyverse)
- library(plotly)
- #reading
- flight<-read.csv('flight.csv')
- airports<-read.csv('airports.csv')
- flighsort<-flight[order(flight$airline),]
- #airports locations
- airports<-read.csv('airports.csv')
- #clearning data for map
- #converting lon_Dest_airport from factor to character to map it
- AirportsMap <- flight %>%
- mutate(lon_Dest_airport = parse_number(as.character(lon_Dest_airport)))
- #cleaning the original file to get the number of flights between each two airports
- AirportsMap<-AirportsMap %>% group_by(origin_airport,dest_airport,lon_origin_airport,lat_origin_airport,
- lon_Dest_airport,lat_Dest_airport) %>% tally()
- #drawing the map
- geo <- list(
- scope = 'usa',
- projection = list(type = 'world'),
- showland = TRUE,
- landcolor = toRGB("gray95"),
- countrycolor = toRGB("gray80")
- )
- #adding marker for the three origin airports
- plot_geo(locationmode = 'USA-states') %>%
- add_markers(
- data=airports, x = ~lon, y = ~lat, text=~airport,size = 0.1,
- hoverinfo = "text",alpha = 0.5) %>%
- #adding flights routes
- add_segments(
- data = AirportsMap,
- x = ~lon_origin_airport, xend = ~lon_Dest_airport,
- y = ~lat_origin_airport, yend = ~lat_Dest_airport,
- alpha = 0.3
- ) %>%
- #adding a title
- layout(
- title = 'NYC Flights 2013<br>(Hover for airport names)',
- geo = geo, showlegend = FALSE
- )
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement