Advertisement
Guest User

Untitled

a guest
Jun 17th, 2019
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.35 KB | None | 0 0
  1. library(tidyverse)
  2. library(plotly)
  3.  
  4. #reading
  5. flight<-read.csv('flight.csv')
  6. airports<-read.csv('airports.csv')
  7. flighsort<-flight[order(flight$airline),]
  8.  
  9.  
  10. #airports locations
  11. airports<-read.csv('airports.csv')
  12.  
  13.  
  14. #clearning data for map
  15. #converting lon_Dest_airport from factor to character to map it
  16. AirportsMap <- flight %>%
  17. mutate(lon_Dest_airport = parse_number(as.character(lon_Dest_airport)))
  18.  
  19. #cleaning the original file to get the number of flights between each two airports
  20. AirportsMap<-AirportsMap %>% group_by(origin_airport,dest_airport,lon_origin_airport,lat_origin_airport,
  21. lon_Dest_airport,lat_Dest_airport) %>% tally()
  22. #drawing the map
  23. geo <- list(
  24. scope = 'usa',
  25. projection = list(type = 'world'),
  26. showland = TRUE,
  27. landcolor = toRGB("gray95"),
  28. countrycolor = toRGB("gray80")
  29. )
  30.  
  31. #adding marker for the three origin airports
  32. plot_geo(locationmode = 'USA-states') %>%
  33. add_markers(
  34. data=airports, x = ~lon, y = ~lat, text=~airport,size = 0.1,
  35. hoverinfo = "text",alpha = 0.5) %>%
  36. #adding flights routes
  37. add_segments(
  38. data = AirportsMap,
  39. x = ~lon_origin_airport, xend = ~lon_Dest_airport,
  40. y = ~lat_origin_airport, yend = ~lat_Dest_airport,
  41. alpha = 0.3
  42. ) %>%
  43. #adding a title
  44. layout(
  45. title = 'NYC Flights 2013<br>(Hover for airport names)',
  46. geo = geo, showlegend = FALSE
  47. )
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement