A data story about trajectories

Requirement: Creating trajectories for representing spatial-temporal patterns of moving objects.

The assignment should include:

Visualization outputs: plots of trajectories

Text descriptions (describe the data and plots, your observations, and possible explanations) at least 150 words (in English) or 500 words (in Chinese)

rm(list=ls()) #clear all
#install.packages("trajectories")
#install.packages("maptiles")
#install.packages("raster")
library(sp)
library(sf)
library(xts)
library(spacetime)
library(trajectories)
library(maptiles)
library(raster)
library(RColorBrewer)

Raw data

Data Source: Typhoon trajectories in Japan, https://www.data.jma.go.jp/yoho/typhoon/position_table/table2021.html

setwd("~/Downloads")
#install.packages("readr")
library(readr)
d=read_csv("table2021.csv",locale = locale(encoding = "SHIFT-JIS"))

Building “Track” objects

x=d$経度
y=d$緯度
pts = cbind(x,y)
crs = CRS("+proj=longlat +ellps=WGS84") # longlat
sp_pts <- SpatialPoints(pts,crs)
# time 
library(dplyr)
td=d[,c(1:4)]
td$年=td$年 %>% as.character()
td$月=td$月 %>% as.character()
td$日=td$日 %>% as.character()
td$`時(UTC)`=td$`時(UTC)` %>% as.character()
# combine them tog
d$time=paste0(td$年,"-0",td$月,"-",td$日,"-",td$`時(UTC)`)
d$time1 <- as.POSIXct(d$time,format="%Y-%m-%d-%H")
stidf = STIDF(sp_pts, d$time1,data.frame(name =d$台風名))
A1 = Track(stidf)
plot(A1,lwd=2)

dim(A1) 
## geometries 
##        461
stbox(A1)
##         x    y                time
## min  99.3  5.8 2021-02-16 06:00:00
## max 184.1 51.9 2021-09-26 00:00:00
###############
d=d %>% filter(台風名=="CEMPAKA")
d=d %>% filter(台風名=="CHAMPI")
d=d %>% filter(台風名=="CHANTHU")
d=d %>% filter(台風名=="CHOI-WAN")
d=d %>% filter(台風名=="CONSON")
d=d %>% filter(台風名=="DIANMU")
d=d %>% filter(台風名=="DUJUAN")
d=d %>% filter(台風名=="IN-FA")
d=d %>% filter(台風名=="KOGUMA")
d=d %>% filter(台風名=="LUPIT")
d=d %>% filter(台風名=="MIRINAE")
d=d %>% filter(台風名=="NEPARTAK")
d=d %>% filter(台風名=="NIDA")
d=d %>% filter(台風名=="OMAIS")
d=d %>% filter(台風名=="SURIGAE")
###############

table(d$台風名)
## < table of extent 0 >
###########################################
setwd("~/Downloads")
#install.packages("readr")
library(readr)
d=read_csv("table2021.csv",locale = locale(encoding = "SHIFT-JIS"))
## Building "TracksCollection" objects
library(dplyr)

d=d %>% filter(台風名=="CEMPAKA")
x=d$経度
y=d$緯度
pts = cbind(x,y)
crs = CRS("+proj=longlat +ellps=WGS84") # longlat
sp_pts <- SpatialPoints(pts,crs)
# time 
td=d[,c(1:4)]
td$年=td$年 %>% as.character()
td$月=td$月 %>% as.character()
td$日=td$日 %>% as.character()
td$`時(UTC)`=td$`時(UTC)` %>% as.character()
# combine them tog
d$time=paste0(td$年,"-0",td$月,"-",td$日,"-",td$`時(UTC)`)
d$time1 <- as.POSIXct(d$time,format="%Y-%m-%d-%H")
stidf = STIDF(sp_pts, d$time1,data.frame(name =d$台風名))
A1 = Track(stidf)
#################################################################

###########################################
setwd("~/Downloads")
#install.packages("readr")
library(readr)
d=read_csv("table2021.csv",locale = locale(encoding = "SHIFT-JIS"))
## Building "TracksCollection" objects
library(dplyr)
d=d %>% filter(台風名=="CHAMPI")
x=d$経度
y=d$緯度
pts = cbind(x,y)
crs = CRS("+proj=longlat +ellps=WGS84") # longlat
sp_pts <- SpatialPoints(pts,crs)
# time 
td=d[,c(1:4)]
td$年=td$年 %>% as.character()
td$月=td$月 %>% as.character()
td$日=td$日 %>% as.character()
td$`時(UTC)`=td$`時(UTC)` %>% as.character()
# combine them tog
d$time=paste0(td$年,"-0",td$月,"-",td$日,"-",td$`時(UTC)`)
d$time1 <- as.POSIXct(d$time,format="%Y-%m-%d-%H")
stidf = STIDF(sp_pts, d$time1,data.frame(name =d$台風名))
A2 = Track(stidf)
#################################################################

###########################################
setwd("~/Downloads")
#install.packages("readr")
library(readr)
d=read_csv("table2021.csv",locale = locale(encoding = "SHIFT-JIS"))
## Building "TracksCollection" objects
library(dplyr)
d=d %>% filter(台風名=="CHANTHU")
x=d$経度
y=d$緯度
pts = cbind(x,y)
crs = CRS("+proj=longlat +ellps=WGS84") # longlat
sp_pts <- SpatialPoints(pts,crs)
# time 
td=d[,c(1:4)]
td$年=td$年 %>% as.character()
td$月=td$月 %>% as.character()
td$日=td$日 %>% as.character()
td$`時(UTC)`=td$`時(UTC)` %>% as.character()
# combine them tog
d$time=paste0(td$年,"-0",td$月,"-",td$日,"-",td$`時(UTC)`)
d$time1 <- as.POSIXct(d$time,format="%Y-%m-%d-%H")
stidf = STIDF(sp_pts, d$time1,data.frame(name =d$台風名))
A3 = Track(stidf)
#################################################################

###########################################
setwd("~/Downloads")
#install.packages("readr")
library(readr)
d=read_csv("table2021.csv",locale = locale(encoding = "SHIFT-JIS"))
## Building "TracksCollection" objects
library(dplyr)
d=d %>% filter(台風名=="CHOI-WAN")
x=d$経度
y=d$緯度
pts = cbind(x,y)
crs = CRS("+proj=longlat +ellps=WGS84") # longlat
sp_pts <- SpatialPoints(pts,crs)
# time 
td=d[,c(1:4)]
td$年=td$年 %>% as.character()
td$月=td$月 %>% as.character()
td$日=td$日 %>% as.character()
td$`時(UTC)`=td$`時(UTC)` %>% as.character()
# combine them tog
d$time=paste0(td$年,"-0",td$月,"-",td$日,"-",td$`時(UTC)`)
d$time1 <- as.POSIXct(d$time,format="%Y-%m-%d-%H")
stidf = STIDF(sp_pts, d$time1,data.frame(name =d$台風名))
A4 = Track(stidf)
#################################################################

###########################################
setwd("~/Downloads")
#install.packages("readr")
library(readr)
d=read_csv("table2021.csv",locale = locale(encoding = "SHIFT-JIS"))
## Building "TracksCollection" objects
library(dplyr)
d=d %>% filter(台風名=="CONSON")
x=d$経度
y=d$緯度
pts = cbind(x,y)
crs = CRS("+proj=longlat +ellps=WGS84") # longlat
sp_pts <- SpatialPoints(pts,crs)
# time 
td=d[,c(1:4)]
td$年=td$年 %>% as.character()
td$月=td$月 %>% as.character()
td$日=td$日 %>% as.character()
td$`時(UTC)`=td$`時(UTC)` %>% as.character()
# combine them tog
d$time=paste0(td$年,"-0",td$月,"-",td$日,"-",td$`時(UTC)`)
d$time1 <- as.POSIXct(d$time,format="%Y-%m-%d-%H")
stidf = STIDF(sp_pts, d$time1,data.frame(name =d$台風名))
A5 = Track(stidf)
#################################################################

###########################################
setwd("~/Downloads")
#install.packages("readr")
library(readr)
d=read_csv("table2021.csv",locale = locale(encoding = "SHIFT-JIS"))
## Building "TracksCollection" objects
library(dplyr)
d=d %>% filter(台風名=="DIANMU")
x=d$経度
y=d$緯度
pts = cbind(x,y)
crs = CRS("+proj=longlat +ellps=WGS84") # longlat
sp_pts <- SpatialPoints(pts,crs)
# time 
td=d[,c(1:4)]
td$年=td$年 %>% as.character()
td$月=td$月 %>% as.character()
td$日=td$日 %>% as.character()
td$`時(UTC)`=td$`時(UTC)` %>% as.character()
# combine them tog
d$time=paste0(td$年,"-0",td$月,"-",td$日,"-",td$`時(UTC)`)
d$time1 <- as.POSIXct(d$time,format="%Y-%m-%d-%H")
stidf = STIDF(sp_pts, d$time1,data.frame(name =d$台風名))
A6 = Track(stidf)
#################################################################

###########################################
setwd("~/Downloads")
#install.packages("readr")
library(readr)
d=read_csv("table2021.csv",locale = locale(encoding = "SHIFT-JIS"))
## Building "TracksCollection" objects
library(dplyr)
d=d %>% filter(台風名=="DUJUAN")
x=d$経度
y=d$緯度
pts = cbind(x,y)
crs = CRS("+proj=longlat +ellps=WGS84") # longlat
sp_pts <- SpatialPoints(pts,crs)
# time 
td=d[,c(1:4)]
td$年=td$年 %>% as.character()
td$月=td$月 %>% as.character()
td$日=td$日 %>% as.character()
td$`時(UTC)`=td$`時(UTC)` %>% as.character()
# combine them tog
d$time=paste0(td$年,"-0",td$月,"-",td$日,"-",td$`時(UTC)`)
d$time1 <- as.POSIXct(d$time,format="%Y-%m-%d-%H")
stidf = STIDF(sp_pts, d$time1,data.frame(name =d$台風名))
A7 = Track(stidf)
#################################################################

###########################################
setwd("~/Downloads")
#install.packages("readr")
library(readr)
d=read_csv("table2021.csv",locale = locale(encoding = "SHIFT-JIS"))
## Building "TracksCollection" objects
library(dplyr)
d=d %>% filter(台風名=="IN-FA")
x=d$経度
y=d$緯度
pts = cbind(x,y)
crs = CRS("+proj=longlat +ellps=WGS84") # longlat
sp_pts <- SpatialPoints(pts,crs)
# time 
td=d[,c(1:4)]
td$年=td$年 %>% as.character()
td$月=td$月 %>% as.character()
td$日=td$日 %>% as.character()
td$`時(UTC)`=td$`時(UTC)` %>% as.character()
# combine them tog
d$time=paste0(td$年,"-0",td$月,"-",td$日,"-",td$`時(UTC)`)
d$time1 <- as.POSIXct(d$time,format="%Y-%m-%d-%H")
stidf = STIDF(sp_pts, d$time1,data.frame(name =d$台風名))
A8 = Track(stidf)
#################################################################

###########################################
setwd("~/Downloads")
#install.packages("readr")
library(readr)
d=read_csv("table2021.csv",locale = locale(encoding = "SHIFT-JIS"))
## Building "TracksCollection" objects
library(dplyr)
d=d %>% filter(台風名=="KOGUMA")
x=d$経度
y=d$緯度
pts = cbind(x,y)
crs = CRS("+proj=longlat +ellps=WGS84") # longlat
sp_pts <- SpatialPoints(pts,crs)
# time 
td=d[,c(1:4)]
td$年=td$年 %>% as.character()
td$月=td$月 %>% as.character()
td$日=td$日 %>% as.character()
td$`時(UTC)`=td$`時(UTC)` %>% as.character()
# combine them tog
d$time=paste0(td$年,"-0",td$月,"-",td$日,"-",td$`時(UTC)`)
d$time1 <- as.POSIXct(d$time,format="%Y-%m-%d-%H")
stidf = STIDF(sp_pts, d$time1,data.frame(name =d$台風名))
A9 = Track(stidf)
#################################################################


###########################################
setwd("~/Downloads")
#install.packages("readr")
library(readr)
d=read_csv("table2021.csv",locale = locale(encoding = "SHIFT-JIS"))
## Building "TracksCollection" objects
library(dplyr)
d=d %>% filter(台風名=="LUPIT")
x=d$経度
y=d$緯度
pts = cbind(x,y)
crs = CRS("+proj=longlat +ellps=WGS84") # longlat
sp_pts <- SpatialPoints(pts,crs)
# time 
td=d[,c(1:4)]
td$年=td$年 %>% as.character()
td$月=td$月 %>% as.character()
td$日=td$日 %>% as.character()
td$`時(UTC)`=td$`時(UTC)` %>% as.character()
# combine them tog
d$time=paste0(td$年,"-0",td$月,"-",td$日,"-",td$`時(UTC)`)
d$time1 <- as.POSIXct(d$time,format="%Y-%m-%d-%H")
stidf = STIDF(sp_pts, d$time1,data.frame(name =d$台風名))
A10 = Track(stidf)
#################################################################

###########################################
setwd("~/Downloads")
#install.packages("readr")
library(readr)
d=read_csv("table2021.csv",locale = locale(encoding = "SHIFT-JIS"))
## Building "TracksCollection" objects
library(dplyr)
d=d %>% filter(台風名=="MIRINAE")
x=d$経度
y=d$緯度
pts = cbind(x,y)
crs = CRS("+proj=longlat +ellps=WGS84") # longlat
sp_pts <- SpatialPoints(pts,crs)
# time 
td=d[,c(1:4)]
td$年=td$年 %>% as.character()
td$月=td$月 %>% as.character()
td$日=td$日 %>% as.character()
td$`時(UTC)`=td$`時(UTC)` %>% as.character()
# combine them tog
d$time=paste0(td$年,"-0",td$月,"-",td$日,"-",td$`時(UTC)`)
d$time1 <- as.POSIXct(d$time,format="%Y-%m-%d-%H")
stidf = STIDF(sp_pts, d$time1,data.frame(name =d$台風名))
A11 = Track(stidf)
#################################################################

###########################################
setwd("~/Downloads")
#install.packages("readr")
library(readr)
d=read_csv("table2021.csv",locale = locale(encoding = "SHIFT-JIS"))
## Building "TracksCollection" objects
library(dplyr)
d=d %>% filter(台風名=="NEPARTAK")
x=d$経度
y=d$緯度
pts = cbind(x,y)
crs = CRS("+proj=longlat +ellps=WGS84") # longlat
sp_pts <- SpatialPoints(pts,crs)
# time 
td=d[,c(1:4)]
td$年=td$年 %>% as.character()
td$月=td$月 %>% as.character()
td$日=td$日 %>% as.character()
td$`時(UTC)`=td$`時(UTC)` %>% as.character()
# combine them tog
d$time=paste0(td$年,"-0",td$月,"-",td$日,"-",td$`時(UTC)`)
d$time1 <- as.POSIXct(d$time,format="%Y-%m-%d-%H")
stidf = STIDF(sp_pts, d$time1,data.frame(name =d$台風名))
A12 = Track(stidf)
#################################################################

###########################################
setwd("~/Downloads")
#install.packages("readr")
library(readr)
d=read_csv("table2021.csv",locale = locale(encoding = "SHIFT-JIS"))
## Building "TracksCollection" objects
library(dplyr)
d=d %>% filter(台風名=="NIDA")
x=d$経度
y=d$緯度
pts = cbind(x,y)
crs = CRS("+proj=longlat +ellps=WGS84") # longlat
sp_pts <- SpatialPoints(pts,crs)
# time 
td=d[,c(1:4)]
td$年=td$年 %>% as.character()
td$月=td$月 %>% as.character()
td$日=td$日 %>% as.character()
td$`時(UTC)`=td$`時(UTC)` %>% as.character()
# combine them tog
d$time=paste0(td$年,"-0",td$月,"-",td$日,"-",td$`時(UTC)`)
d$time1 <- as.POSIXct(d$time,format="%Y-%m-%d-%H")
stidf = STIDF(sp_pts, d$time1,data.frame(name =d$台風名))
A13 = Track(stidf)
#################################################################

###########################################
setwd("~/Downloads")
#install.packages("readr")
library(readr)
d=read_csv("table2021.csv",locale = locale(encoding = "SHIFT-JIS"))
## Building "TracksCollection" objects
library(dplyr)
d=d %>% filter(台風名=="OMAIS")
x=d$経度
y=d$緯度
pts = cbind(x,y)
crs = CRS("+proj=longlat +ellps=WGS84") # longlat
sp_pts <- SpatialPoints(pts,crs)
# time 
td=d[,c(1:4)]
td$年=td$年 %>% as.character()
td$月=td$月 %>% as.character()
td$日=td$日 %>% as.character()
td$`時(UTC)`=td$`時(UTC)` %>% as.character()
# combine them tog
d$time=paste0(td$年,"-0",td$月,"-",td$日,"-",td$`時(UTC)`)
d$time1 <- as.POSIXct(d$time,format="%Y-%m-%d-%H")
stidf = STIDF(sp_pts, d$time1,data.frame(name =d$台風名))
A14 = Track(stidf)
#################################################################

###########################################
setwd("~/Downloads")
#install.packages("readr")
library(readr)
d=read_csv("table2021.csv",locale = locale(encoding = "SHIFT-JIS"))
## Building "TracksCollection" objects
library(dplyr)
d=d %>% filter(台風名=="SURIGAE")
x=d$経度
y=d$緯度
pts = cbind(x,y)
crs = CRS("+proj=longlat +ellps=WGS84") # longlat
sp_pts <- SpatialPoints(pts,crs)
# time 
td=d[,c(1:4)]
td$年=td$年 %>% as.character()
td$月=td$月 %>% as.character()
td$日=td$日 %>% as.character()
td$`時(UTC)`=td$`時(UTC)` %>% as.character()
# combine them tog
d$time=paste0(td$年,"-0",td$月,"-",td$日,"-",td$`時(UTC)`)
d$time1 <- as.POSIXct(d$time,format="%Y-%m-%d-%H")
stidf = STIDF(sp_pts, d$time1,data.frame(name =d$台風名))
A15 = Track(stidf)
#################################################################


# Tracks for person B:
B=Tracks(list(p1=A1,p2=A2,CHANTHU=A3,CHOIWAN=A4,CONSON=A5,DIANMU=A6,DUJUAN=A7,INFA=A8,KOGUMA=A9,LUPIT=A10,MIRINAE=A11,NEPARTAK=A12,NIDA=A13,OMAIS=A14,SURIGAE=A15))


# Using plot() for adding a base map

bbA1 <- stbox(B)
xmin <- bbA1[1,1]; ymin <- bbA1[1,2]
xmax <- bbA1[2,1]; ymax <- bbA1[2,2]

bbox1 = st_bbox(c(xmin = xmin, ymin = ymin, 
                  xmax = xmax, ymax = ymax), 
                crs = st_crs(4326))

basemap1 = get_tiles(bbox1, crop = T)


plot(basemap1,title="Typhoon in Japan, 2021")
plot(B,lwd=2, col="red", add=TRUE)

setwd("~/Downloads")
#install.packages("readr")
library(readr)
d=read_csv("table2021.csv",locale = locale(encoding = "SHIFT-JIS"))
x=d$経度
y=d$緯度
pts = cbind(x,y)
crs = CRS("+proj=longlat +ellps=WGS84") # longlat
sp_pts <- SpatialPoints(pts,crs)
# time 
td=d[,c(1:4)]
td$年=td$年 %>% as.character()
td$月=td$月 %>% as.character()
td$日=td$日 %>% as.character()
td$`時(UTC)`=td$`時(UTC)` %>% as.character()
# combine them tog
d$time=paste0(td$年,"-0",td$月,"-",td$日,"-",td$`時(UTC)`)
d$time1 <- as.POSIXct(d$time,format="%Y-%m-%d-%H")
#stidf = STIDF(sp_pts, d$time1,data.frame(name =d$台風名))
#A = Track(stidf)
#################################################################

library(ggplot2)
library(ggmap)
cbbox <- make_bbox(lon = d$経度, lat = d$緯度, f = .1) #from ggmap
sq_map <- get_map(location = cbbox, maptype = "satellite", source = "google")

names(d)[6]="TyphoonName"

ggmap(sq_map) + 
  geom_path(data = d, aes(x = 経度, y =緯度, color = TyphoonName), 
            size = 1, lineend = "round") +
  labs(x = " ", y = " ", title = "Typhoon Trajectories around Japan, Asia in 2021") +
  theme_minimal() 

ggmap(sq_map) + 
  geom_path(data = d, aes(x = 経度, y =緯度, color = TyphoonName), 
            size = 1, lineend = "round") +
  labs(x = " ", y = " ", title = "Typhoon Trajectories around Japan, Asia in 2021") +
  theme_minimal()+
facet_wrap(~ TyphoonName)

names(d)[20]="TyphoonTime"
ggmap(sq_map) + 
  geom_path(data = d, aes(x = 経度, y =緯度, color = TyphoonTime), 
            size = 1, lineend = "round") +
  labs(x = " ", y = " ", title = "Typhoon Trajectories around Japan, Asia in 2021") 

names(d)[11]="LargestWindSpeed"
ggmap(sq_map) + 
  geom_path(data = d, aes(x = 経度, y =緯度, color =LargestWindSpeed), 
            size = 1, lineend = "round") +
  labs(x = " ", y = " ", title = "Typhoon Trajectories around Japan, Asia in 2021") 

Text descriptions:

The typhoon trajectories data is from the open data plaform of Japan governement. There are 15 typhoons occuring from Feb, 2021 to Sep, 2021 recorded in the data. It start with the name Chempaka and end with Surigae.

As showed in the plot, the typhoon occurs near Pacific Ocean in the west of Japan. Each typhoon has different tracks. Some of them turn northward and others turn southward.

What I found that is interesting is that in Early summer around July, typhoon appears in Pacific ocean but in the late summer, typhoon appears more east to the land sides. The darker the line is, the earlier the typhoons appear.