You are on page 1of 2

# Código de Vuelo

# World map is available in the maps package


library(maps)

# No margin
par(mar=c(0,0,0,0))

# World map
map('world',
col="#f2f2f2", fill=TRUE, bg="white", lwd=0.05,
mar=rep(0,4),border=0, ylim=c(-80,80)
)

# Dplyr for data wrangling and pipe function


library(dplyr)

# Cities (Longitud, Latitud)


City_1 <- c(-134.146, 63.5125)
City_2 <- c(-119.366, 61.543)
City_3 <- c(42.314, 30.317)
City_4 <- c(63.5125, 45.854)
City_5 <- c(119.366, 21.157)

# Data frame
data <- rbind(City_1, City_2, City_3, City_4, City_5) %>%
as.data.frame()
colnames(data) <- c("long","lat")

# Show the cities on the map


map('world',
col="#f2f2f2", fill=TRUE, bg="white", lwd=0.05,
mar=rep(0,4),border=0, ylim=c(-80,80)
)
points(x=data$long, y=data$lat, col="slateblue", cex=3, pch=20)

# Load geosphere
library(geosphere)

# Background map
map('world',
col="#f2f2f2", fill=TRUE, bg="white", lwd=0.05,
mar=rep(0,4),border=0, ylim=c(-80,80)
)

# Dot for cities


points(x=data$long, y=data$lat, col="slateblue", cex=3, pch=20)

# Compute the connection between City_1 and City_2


inter <- gcIntermediate(City_1, City_2, n=50, addStartEnd=TRUE, breakAtDateLine=F)

# Show this connection


lines(inter, col="slateblue", lwd=2)

# Compute the connection between City_1 and City_3


inter <- gcIntermediate(City_1, City_3, n=50, addStartEnd=TRUE, breakAtDateLine=F)
# Show this connection
lines(inter, col="slateblue", lwd=2)

# Compute the connection between City_1 and City_4


inter <- gcIntermediate(City_1, City_4, n=50, addStartEnd=TRUE, breakAtDateLine=F)

# Show this connection


lines(inter, col="slateblue", lwd=2)

# Compute the connection between City_1 and City_5


inter <- gcIntermediate(City_1, City_5, n=50, addStartEnd=TRUE, breakAtDateLine=F)

# Show this connection


lines(inter, col="slateblue", lwd=2)

You might also like