如何用R语言绘制连接路径图(从布宜诺斯艾利斯经巴黎-北京-南京-广州至墨尔本)

# Dplyr for data wrangling and pipe function
library(dplyr)
# Load geosphere
library(geosphere)
library(maps)
# Background map
map('world',
    col="#f2f2f2", fill=TRUE, bg="white", lwd=0.05,
    mar=rep(0,4),border=0, ylim=c(-80,80) 
)
# Cities
Buenos_aires <- c(-58,-34)
Paris <- c(2,49)
Melbourne <- c(145,-38)
Beijing<-c(117.4,41.6)
Nanjing=c(119.14,31.14)
GuangZhou=c(113.27,23.13)

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

# Compute the connection between Buenos Aires and Paris
inter <- gcIntermediate(Paris,  Buenos_aires, n=50, addStartEnd=TRUE, breakAtDateLine=F)



# Data frame
data <- rbind(Buenos_aires, Paris, Melbourne,Beijing,Nanjing,GuangZhou) %>% 
  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)
# Show this connection
lines(inter, col="slateblue", lwd=2)

# Between Paris and Beijing
inter <- gcIntermediate(Beijing, Paris, n=50, addStartEnd=TRUE, breakAtDateLine=F)             
lines(inter, col="slateblue", lwd=2)
# Between Nanjing and Beijing
inter <- gcIntermediate(Nanjing, Beijing, n=50, addStartEnd=TRUE, breakAtDateLine=F)             
lines(inter, col="slateblue", lwd=2)
# Between Nanjing and GuangZhou
inter <- gcIntermediate(GuangZhou, Nanjing, n=50, addStartEnd=TRUE, breakAtDateLine=F)             
lines(inter, col="slateblue", lwd=2)
# Between Melbourne and GuangZhou
inter <- gcIntermediate(Melbourne, GuangZhou, n=50, addStartEnd=TRUE, breakAtDateLine=F)             
lines(inter, col="slateblue", lwd=2)

在这里插入图片描述
参考文献:https://bbs.huaweicloud.com/blogs/407370

猜你喜欢

转载自blog.csdn.net/m0_38127487/article/details/132127329