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)
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
mapview(epa,label = "SiteName", layer.name = "Observatory")
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)
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))