空間分析  實習四

助教 杜承軒 2021.04.07

描述疾病擴散的時空趨勢。


*初步環境建置與讀取檔案

library(sf);library(aspace);library(tmap)
setwd("D:/1092SA/Data")
windowsFonts(TOP=windowsFont("Topedia Sans TW Beta"))
Dengue=st_read("point_event.shp")
TW=st_read("Popn_TWN2.shp", options="ENCODING=BIG5")
st_crs(Dengue)=st_crs(TW)

Task 1: Exploring temporal trends in different time-scales
By Week & By Period

Dengue$period=ceiling((Dengue$WEEK+1)/8)
ggplot(Dengue)+geom_bar(aes(x=period))+xlab("時段")+ylab("病例數")+
 scale_x_continuous(breaks = 1:7)+theme_minimal()+theme(text=element_text(family="TOP"))

ggplot(Dengue)+geom_bar(aes(x=WEEK))+xlab("週次")+ylab("病例數")+
 scale_x_continuous(breaks = seq(0,55,5))+theme_minimal()+theme(text=element_text(family="TOP"))


Task 2: Exploring spatial trends in different periods
擷取高雄地區的登革熱病例分佈

KH=TW[TW$COUNTY=='高雄市',]
IN=st_contains(st_union(KH),Dengue,sparse=F)
KH.Dengue=Dengue[IN,]
KD=KH.Dengue%>%st_drop_geometry

Standard Distance

col=RColorBrewer::brewer.pal(7,"Reds")
map=tm_shape(KH,xlim=c(16,20)*10^4,ylim=c(249,252)*10^4)+tm_borders()
for(i in 1:7){
 KDi=KD[KD$period==i,c(2,3)]
 calc_sdd(points=KDi)
 CENTRE=c(sddatt$CENTRE.x, sddatt$CENTRE.y)
 CENTRE.sf=CENTRE%>%st_point%>%st_sfc%>%st_sf
 st_crs(CENTRE.sf)=st_crs(KH)
 rad = sddatt$SDD.radius
 SDD = st_buffer(CENTRE.sf, rad)
 map=map+tm_shape(CENTRE.sf)+tm_symbols(0.5,col[i])+tm_shape(SDD)+tm_borders(col[i],2)
}
map+tm_layout(frame=F)


Standard Deviational Ellipse

col=c('red','orange','gold','green4','deepskyblue','blue','purple')
map=tm_shape(KH,xlim=c(16,20)*10^4,ylim=c(249,252)*10^4)+tm_borders()
for(i in 1:7){
 KDi=KD[KD$period==i,c(2,3)]
 calc_sde(points=KDi)
 CENTRE=c(sdeatt$CENTRE.x, sdeatt$CENTRE.y)
 CENTRE.sf=CENTRE%>%st_point%>%st_sfc%>%st_sf
 st_crs(CENTRE.sf)=st_crs(KH)
 SDE.data = data.frame(x= sdeloc$x, y= sdeloc$y)
 SDE.pt.sf= st_as_sf(SDE.data , coords=c("x","y"))
 st_crs(SDE.pt.sf)=st_crs(KH)
 SDE.poly = st_cast(st_combine(SDE.pt.sf),"POLYGON") 
 SDE.sf   = st_sf(SDE.poly)
 map=map+tm_shape(CENTRE.sf)+tm_symbols(0.5,col[i])+tm_shape(SDE.sf)+tm_borders(col[i],2)
}
map+tm_layout(frame=F)