r - Trying to generate maps for flight departures and arrivals -


the script below works, seems stuck on line.

mappoints <- ggmap(map) +   geom_point(aes(x = lon, y = lat, size = sqrt(flights)), data = airportd, alpha = .5) 

here entire thing.

airports <- read.csv("https://raw.githubusercontent.com/jpatokal/openflights/master/data/airports.dat", header = false) colnames(airports) <- c("id", "name", "city", "country", "iata_faa", "icao", "lat", "lon", "altitude", "timezone", "dst") # head(airports)  library(rworldmap) newmap <- getmap(resolution = "low") par(mar = rep(2, 4)) plot(newmap, xlim = c(-20, 59), ylim = c(35, 71), asp = 1) points(airports$lon, airports$lat, col = "red", cex = .6)   routes <- read.csv("https://raw.githubusercontent.com/jpatokal/openflights/master/data/routes.dat", header=f) colnames(routes) <- c("airline", "airlineid", "sourceairport", "sourceairportid", "destinationairport", "destinationairportid", "codeshare", "stops", "equipment") # head(routes)   library(plyr) departures <- ddply(routes, .(sourceairportid), "nrow") names(departures)[2] <- "flights" arrivals <- ddply(routes, .(destinationairportid), "nrow") names(arrivals)[2] <- "flights"   airportd <- merge(airports, departures, by.x = "id", by.y = "sourceairportid") airporta <- merge(airports, arrivals, by.x = "id", by.y = "destinationairportid")  library(ggmap) map <- get_map(location = 'europe', zoom = 4)  mappoints <- ggmap(map) + geom_point(aes(x = lon, y = lat, size = sqrt(flights)), data = airportd, alpha = .5)  mappointslegend <- mappoints +   scale_area(breaks = sqrt(c(1, 5, 10, 50, 100, 500)), labels = c(1, 5, 10, 50, 100, 500), name = "departing routes")  mappointslegend    # create data set containing both departures , arrivals airportd$type <- "departures" airporta$type <- "arrivals" airportda <- rbind(airportd, airporta)  # map data # map + data points mappointsda <- ggmap(map) + geom_point(aes(x = lon, y = lat, size = sqrt(flights)), data = airportda, alpha = .5) # adjust legend mappointslegendda <- mappointsda + scale_area(breaks = sqrt(c(1, 5, 10, 50, 100, 500)), labels = c(1, 5, 10, 50, 100, 500), name = "routes") # panels according type (departure/arrival) mappointsfacetsda <- mappointslegendda + facet_grid(. ~ type) # plot map mappointsfacetsda 

the script comes link directly below. notice: data sets in different place suggested in link; corrected in script.

http://www.milanor.net/blog/maps-in-r-plotting-data-points-on-a-map/

i googled solution , i'm stumped. ideas?

here message i'm getting.

enter image description here

your environment little old , recommend update r , packages. use r version 3.3.2 (2016-10-31) in r studio version 1.0.44 (desktop) , plyr version 1.8.4, ggmap version 2.6.1, , ggplot2 version 2.1.0. below example code works in env. messages get_map() report , last warning means there 5458 data outside of europe.

library(ggplot2); library(ggmap); library(plyr)  airports <- read.csv("https://raw.githubusercontent.com/jpatokal/openflights/master/data/airports.dat", header = false) routes <- read.csv("https://raw.githubusercontent.com/jpatokal/openflights/master/data/routes.dat", header=f)  colnames(airports) <- c("id", "name", "city", "country", "iata_faa", "icao", "lat", "lon", "altitude", "timezone", "dst") colnames(routes) <- c("airline", "airlineid", "sourceairport", "sourceairportid", "destinationairport", "destinationairportid", "codeshare", "stops", "equipment")   departures <- ddply(routes, .(sourceairportid), "nrow") names(departures)[2] <- "flights" arrivals <- ddply(routes, .(destinationairportid), "nrow") names(arrivals)[2] <- "flights"  airportd <- merge(airports, departures, by.x = "id", by.y = "sourceairportid") airporta <- merge(airports, arrivals, by.x = "id", by.y = "destinationairportid")  airportd$type <- "departures" airporta$type <- "arrivals" airportda <- rbind(airportd, airporta)  map <- get_map(location = 'europe', zoom = 4)  # map url : http://maps.googleapis.com/maps/api/staticmap?center=europe&zoom=4&size=640x640&scale=2&maptype=terrain&language=en-en&sensor=false # information url : http://maps.googleapis.com/maps/api/geocode/json?address=europe&sensor=false  mappointsda <- ggmap(map) + geom_point(aes(x = lon, y = lat, size = sqrt(flights)), data = airportda, alpha = .5)  mappointslegendda <- mappointsda + scale_size_area(breaks = sqrt(c(1, 5, 10, 50, 100, 500)), labels = c(1, 5, 10, 50, 100, 500), name = "routes") mappointsfacetsda <- mappointslegendda + facet_grid(. ~ type) mappointsfacetsda # warning message: removed 5458 rows containing missing values (geom_point).  

enter image description here


Comments

Popular posts from this blog

java - SSE Emitter : Manage timeouts and complete() -

jquery - uncaught exception: DataTables Editor - remote hosting of code not allowed -

java - How to resolve error - package com.squareup.okhttp3 doesn't exist? -