Скрипт внизу почти работает, но, похоже, застрял на этой линии.Попытка создания карт для вылета и прибытия рейса
mapPoints <- ggmap(map) +
geom_point(aes(x = lon, y = lat, size = sqrt(flights)), data = airportD, alpha = .5)
Вот и все.
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 the data set containing both departures and arrivals
airportD$type <- "departures"
airportA$type <- "arrivals"
airportDA <- rbind(airportD, airportA)
# map the data
# map + data points
mapPointsDA <- ggmap(map) + geom_point(aes(x = lon, y = lat, size = sqrt(flights)), data = airportDA, alpha = .5)
# adjust the 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 to type (departure/arrival)
mapPointsFacetsDA <- mapPointsLegendDA + facet_grid(. ~ type)
# plot the map
mapPointsFacetsDA
Сценарий происходит по прямой ссылке. Обратите внимание: наборы данных находятся в другом месте, чем указано в ссылке; Я уже исправил это в скрипте.
http://www.milanor.net/blog/maps-in-r-plotting-data-points-on-a-map/
Я гугл для решения, и я в тупике. Есть идеи?
Вот сообщение, которое я получаю.
'scale_area()' изменила свое название на 'scale_size_area()', (это связано с вашей проблемой?) – cuttlefish44
Спасибо. Это хорошо знать. Это следующая строка кода. Во-первых, мне нужно получить строку кода прямо перед тем, как вы говорили. –
Странно. Я запускаю RTVS version.string R версии 3.2.3 (2015-12-10). Также попробовал тот же скрипт в RStudio version.string R версии 3.2.2 (2015-08-14). –