オンラインでデータ読み込む場合は、以下のコード。
trade <- read_csv("https://ayumu-tanaka.github.io/teaching/line.csv")
library(readr)
line <- read_csv("line.csv")
head(line)
## # A tibble: 6 × 5
## country import long lat countryname
## <chr> <dbl> <dbl> <dbl> <chr>
## 1 USA 17.9 -113. 45.7 United States
## 2 AUS 9.32 134. -25.7 Australia
## 3 CHN 5.54 104. 36.6 China
## 4 NZL 2.51 171. -41.8 New Zealand
## 5 DEU 1.91 10.4 51.1 Germany
## 6 JPN NA 138. 37.5 Japan
library(readr)
line <- read_csv("line.csv")
USA<-subset(line,country=="USA"|country=="JPN")
library(leaflet)
x<-leaflet()
x<-addTiles(x)
x<-addPolylines(x,lng=USA$long,lat = USA$lat, weight=USA$import)
x
library(readr)
line <- read_csv("line.csv")
USA<-subset(line,country=="USA"|country=="JPN")
AUS<-subset(line,country=="AUS"|country=="JPN")
CHN<-subset(line,country=="CHN"|country=="JPN")
NZL<-subset(line,country=="NZL"|country=="JPN")
DEU<-subset(line,country=="DEU"|country=="JPN")
library(leaflet)
x<- leaflet()
x<- addTiles(x)
x<-addPolylines(x,lng=USA$long,lat = USA$lat, weight=USA$import)
x<-addPolylines(x,lng=AUS$long,lat = AUS$lat, weight=AUS$import)
x<-addPolylines(x,lng=CHN$long,lat = CHN$lat, weight=CHN$import)
x<-addPolylines(x,lng=NZL$long,lat = NZL$lat, weight=NZL$import)
x<-addPolylines(x,lng=DEU$long,lat = DEU$lat, weight=DEU$import)
x
#データ
library(readr)
line <- read_csv("line.csv")
USA<-subset(line,country=="USA"|country=="JPN")
#緯度経度登録
library(geosphere)
JPNcenter <- c(137.96, 37.54)
USAcenter <- c(-112.98, 45.72)
#地図1
gcUSA1 <- gcIntermediate(JPNcenter, USAcenter, addStartEnd = TRUE)
library(leaflet)
y<- leaflet()
y<- addTiles(y)
y<-addPolylines(y,data = gcUSA1,col="red")
y
#データ
library(readr)
line <- read_csv("line.csv")
JPN<-subset(line,country=="JPN")
USA<-subset(line,country=="USA")
#緯度経度登録
library(geosphere)
JPNcenter <- JPN[, c(3:4)]
USAcenter <- USA[, c(3:4)]
#地図2
gcUSA2 <- gcIntermediate(JPNcenter, USAcenter,sp = TRUE,addStartEnd = TRUE, breakAtDateLine=TRUE)
library(leaflet)
y<- leaflet()
y<- addTiles(y)
y<-addPolylines(y,data = gcUSA2,col="blue",weight = USA$import)
y
#データ
library(readr)
line <- read_csv("line.csv")
JPN<-subset(line,country=="JPN")
USA<-subset(line,country=="USA")
AUS<-subset(line,country=="AUS")
CHN<-subset(line,country=="CHN")
NZL<-subset(line,country=="NZL")
DEU<-subset(line,country=="DEU")
#緯度経度登録
library(geosphere)
JPNcenter <- JPN[, c(3:4)]
USAcenter <- USA[, c(3:4)]
AUScenter <- AUS[, c(3:4)]
CHNcenter <- CHN[, c(3:4)]
NZLcenter <- NZL[, c(3:4)]
DEUcenter <- DEU[, c(3:4)]
#地図2
gcUSA2 <- gcIntermediate(JPNcenter, USAcenter,sp = TRUE,addStartEnd = TRUE, breakAtDateLine=TRUE)
gcAUS2 <- gcIntermediate(JPNcenter, AUScenter,sp = TRUE,addStartEnd = TRUE, breakAtDateLine=TRUE)
gcCHN2 <- gcIntermediate(JPNcenter, CHNcenter,sp = TRUE,addStartEnd = TRUE, breakAtDateLine=TRUE)
gcNZL2 <- gcIntermediate(JPNcenter, NZLcenter,sp = TRUE,addStartEnd = TRUE, breakAtDateLine=TRUE)
gcDEU2 <- gcIntermediate(JPNcenter, DEUcenter,sp = TRUE,addStartEnd = TRUE, breakAtDateLine=TRUE)
library(leaflet)
y<- leaflet()
y<- addTiles(y)
y<-addPolylines(y,data = gcUSA2,col="blue",weight = USA$import,
label =USA$import,popup = "USA")
y<-addPolylines(y,data = gcAUS2,col="blue",weight = AUS$import,
label =AUS$import,popup = "AUS")
y<-addPolylines(y,data = gcCHN2,col="blue",weight = CHN$import,
label =CHN$import,popup = "CHN")
y<-addPolylines(y,data = gcNZL2,col="blue",weight = NZL$import,
label =NZL$import,popup = "NZL")
y<-addPolylines(y,data = gcDEU2,col="blue",weight = DEU$import,
label =DEU$import,popup = "DEU")
y
#緯度経度
JPNcenter <- c(137.96, 37.54)
RUScenter<-c(93.85, 66.755)
UKRcenter<-c(30.51069,50.46730)
#航路の計算
library(geosphere)
gcRUS <- gcIntermediate(JPNcenter, RUScenter, addStartEnd = TRUE)
gcUKR <- gcIntermediate(JPNcenter, UKRcenter, addStartEnd = TRUE)
#地図の描画
y<- leaflet()
y<- addTiles(y)
#線の太さは貿易額
y<-addPolylines(y,data = gcRUS,col="blue",weight = 9053904133/100000000)
y<-addPolylines(y,data = gcUKR,col="red",weight = 183662260/100000000)
y