基于R的飞机航线数据可视化(行政区划)

加载库

## 加载库
library(ggplot2)
library(dplyr)
## 
## Attaching package: 'dplyr'
## The following objects are masked from 'package:stats':
## 
##     filter, lag
## The following objects are masked from 'package:base':
## 
##     intersect, setdiff, setequal, union
## 加载库
library(tidyr)
library(RColorBrewer)
library(maps)
library(geosphere)
library(igraph)
## 
## Attaching package: 'igraph'
## The following object is masked from 'package:tidyr':
## 
##     crossing
## The following objects are masked from 'package:dplyr':
## 
##     as_data_frame, groups, union
## The following objects are masked from 'package:stats':
## 
##     decompose, spectrum
## The following object is masked from 'package:base':
## 
##     union
## 加载库
library(networkD3)
library(stringr)

读取数据

## 读取数据,数据融合
routes <- read.csv("routes.csv",header=TRUE)
airports <- read.csv("airports.csv",header=TRUE)

可视化机场位置

map(database = "world",col="skyblue", fill=TRUE, bg="black", lwd=0.1)
# 添加起点的位置
points(x=airports$Longitude, y=airports$Latitude, pch=19, cex=0.2,col="orange")

在这里插入图片描述

可视化每个国家有多少机场

### 可视化每个国家有多少机场
plotdata <- airports%>%group_by(Country)%>%
  summarise(number = n(),
            LatitudeMean = mean(Latitude),
            LongitudeMean = mean(Longitude))


## 在地图上可视化每个国家的机场数量
map(database = "world",col="skyblue", fill=TRUE, bg="black", lwd=0.1)
# 添加起点的位置
points(x=plotdata$LongitudeMean, y=plotdata$LatitudeMean,
       pch=19, cex=log10(plotdata$number),col="orange")

在这里插入图片描述

可视化航线

##  数据组合
plotdata <- routes[c("source.airport","destination.apirport")]
## 剔除缺失值
plotdata <- plotdata[!is.na(plotdata[,1])&!is.na(plotdata[,2]),]
plotdata2 <- airports[c("IATA","Latitude","Longitude")]
plotdata3 <- merge(plotdata,plotdata2,by.x = "source.airport", by.y = "IATA")
plotdata4 <- merge(plotdata3,plotdata2,by.x = "destination.apirport", by.y = "IATA")

## 可视化航线
map(database = "world",col="skyblue", fill=TRUE, bg="black", lwd=0.1)
# 添加起点的位置
points(x=airports$Longitude, y=airports$Latitude, pch=19, cex=0.2,col="orange red")
col.1 <- adjustcolor("orange", alpha=0.4)

for(i in 1:nrow(plotdata4)) {
  node1 <- plotdata4[i,c("Latitude.x","Longitude.x")]
  node2 <- plotdata4[i,c("Latitude.y","Longitude.y")]
  arc <- gcIntermediate( c(node1$Longitude.x, node1$Latitude.x),
                         c(node2$Longitude.y, node2$Latitude.y),
                         n=100, addStartEnd=TRUE )
  lines(arc, col=col.1, lwd=0.1)
}

在这里插入图片描述

更多信息参考 https://rpubs.com/DaiTu/414172

  • 0
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值