R09228001 楊宇翔 台大地理碩二

Data: EPA_timeseries.csv (time-series of the pollutant-CO) Using the time-series data to create an interactive popup graph of the pollutant (CO) for each EPA station hint: using ggplot2 for plotting time-series data

#Load in packages

rm(list=ls(all=TRUE))
library(sf)
library(magrittr)
library(ggplot2)
library(dplyr)
library(leaflet)
library(leafpop)
library(tmap)
library(cartography)
library(mapview)
library(lubridate)

load in data

setwd("~/Desktop/110-1/110-1 data visualization/w6_tmap/GISdata")
library(readxl)
d=read_excel("EPA_timeseries.xlsx") 
epa <- st_read(dsn = "EPA_STN1.shp",options = "encoding=Big5")
## options:        encoding=Big5 
## Reading layer `EPA_STN1' from data source 
##   `/Users/yangyuxiang_1/Desktop/110-1/110-1 data visualization/w6_tmap/GISdata/EPA_STN1.shp' 
##   using driver `ESRI Shapefile'
## Simple feature collection with 73 features and 16 fields
## Geometry type: POINT
## Dimension:     XY
## Bounding box:  xmin: 168247.3 ymin: 2428930 xmax: 330276.4 ymax: 2786121
## Projected CRS: TWD97 / TM2 zone 121

Map the Air quality Observatories

mapview(epa,label = "SiteName", layer.name = "Observatory")

單個Time-series 的視窗的示範

Date與POSIX兩者最大的不同,主要在於儲存的時間資訊量的不同,
Date存年、月、日、星期等信息;然而POSIX類別則可以儲存年、月、日、時、分、秒、時區、星期等訊息。
ggplot(data = d, aes(x = Index, y = 二林 ))+ 
  geom_line()+
    theme(text=element_text(family="黑體-繁 中黑"))+
  ggtitle("二林") +
  xlab('Time')+
  ylab("CO_concentration")+
    stat_smooth(method = "loess", formula = y ~ x, size = 1)

Carbon Monoxide (CO)

CO is a colorless, odorless gas that can be harmful when inhaled in large amounts. CO is released when something is burned. The greatest sources of CO to outdoor air are cars, trucks and other vehicles or machinery that burn fossil fuels. A variety of items in your home such as unvented kerosene and gas space heaters, leaking chimneys and furnaces, and gas stoves also release CO and can affect air quality indoors.

Breathing air with a high concentration of CO reduces the amount of oxygen that can be transported in the blood stream to critical organs like the heart and brain.

At very high levels, which are possible indoors or in other enclosed environments, CO can cause dizziness, confusion, unconsciousness and death.

把Time-Series 放入 pop-out windows

p = list()
for(i in 1:nrow(epa)){
  df <- data.frame(d[,1],d[,i+2])
  colnames(df)=c("time","Concentration_of_CO")
  p[[i]] = ggplot(data = df, aes(x = time, y = Concentration_of_CO ),
         family = "黑體-繁 中黑")+ 
  geom_line(color="orange")+
    theme(text=element_text(family="黑體-繁 中黑"))+
    labs(title = colnames(d)[i+2] ,x = "time",y = "Concentration of CO")+
    stat_smooth(method = "loess", formula = y ~ x, size = 1)
}
mapview(epa, label = "SiteName", layer.name = "Observatory", popup = popupGraph(p))