-
Notifications
You must be signed in to change notification settings - Fork 0
/
airplant.Rmd
68 lines (50 loc) · 1.77 KB
/
airplant.Rmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
---
title: "tw to world"
output: html_document
---
```{r}
library(ggmap)
data.port=read.table(file="C:/Users/TSR/Desktop/°ª²Îr/airports.dat",sep=",")
data.line=read.table(file="C:/Users/TSR/Desktop/°ª²Îr/routes .dat",sep=",")
library(stringr)
portintw <- str_detect(data.port[,'V4'], "Taiwan")
twport <- data.port[portintw,]
data.port= data.port[,c('V3','V5','V7','V8','V9')]
names(data.port) <- c('city','code','lan','lon','att')
twport <-twport[twport$V5!='',
c('V3','V5','V7','V8','V9')]
names(twport) <- c('city','code','lan','lon','att')
lineintw <- data.line[,'V3'] %in% twport$code
twline <- data.line[lineintw,c('V3','V5','V9')]
outport=data.port[data.port$code %in% twline[,"V5"],]
names(twline) <- c('source','destination','equipment')
findposition <- function(code) {
find <- twport$code==code
x <- twport[find,'lon']
y <- twport[find,'lan']
return(data.frame(x,y))
}
too <- function(code) {
find <- data.port$code==code
x <- data.port[find,'lon']
y <- data.port[find,'lan']
return(data.frame(x,y))
}
from <- lapply(as.character(twline$source),findposition)
from <- do.call('rbind',from)
from$group <- 1:dim(from)[1]
names(from) <- c('lon','lan','group')
to <- lapply(as.character(twline$destination),too)
to <- do.call('rbind',to)
to$group <-1:dim(to)[1]
names(to) <-c('lon','lan','group')
data.line <- rbind(from,to)
ggmap(get_googlemap(center = 'taiwan', zoom=3,size=c(1500,1200),
maptype='roadmap'),extent='device')+
geom_point(data=twport,aes(x=lon,y=lan),
colour = 'red4',alpha=0.8)+
geom_point(data=outport,aes(x=lon,y=lan),
colour = 'red4',alpha=0.8)+
geom_line(data=data.line,aes(x=lon,y=lan,group=group),
size=0.1,alpha=1,color='red4')
```