0

I am trying to plot the dataset nycflight 2013. However I can't show the full usa map in r. Airports that are located in Hawaii and Alaska are not showing.

this is my code:

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
  )

any help is appreciated. thanks

ismirsehregal
  • 30,045
  • 5
  • 31
  • 78
sue
  • 41
  • 7
  • some lines have no points at the end – sue May 28 '19 at 00:29
  • I think I need to zoom out to show the end of the connecting lines. but I am not sure how to adjust the map view – sue May 28 '19 at 01:03
  • I am talking about the rest of the lines – sue May 28 '19 at 02:59
  • Can you update your question to make it a bit clearer what you want to do? As it stands you say "Hawaii and Alaska are not showing". But in the image you've posted Hawaii and Alaska *are* showing. – SymbolixAU May 28 '19 at 03:01
  • 2
    Since we don't have any of your data, we can't reproduce any of this. [See here](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) on making a reproducible R example – camille May 28 '19 at 04:01
  • the data exists in R. – sue May 28 '19 at 04:16
  • I don't think the data exists as 'flight.csv' or 'airports.csv' in whatever working directory everyone happens to be in... – Z.Lin May 29 '19 at 08:36

0 Answers0