R/search_city_aqi.R

#' explore city(default nanchang) aqi
#' @author lgm
#' @param city
#' @return aqi of city
#' @export
#' @examples
#' #search_city_aqi()
#'

search_city_aqi <- function(city = "南昌市"){
	nc <- fetch_aqi_sqlite(city)
	ncdf <- as.data.frame(nc)
	ncdf$date <- as.Date(ncdf$date)
	ncdf$AQI <- as.numeric(ncdf$AQI)
	ncdf$weekday <- weekdays(ncdf$date)
	ncdf$weekday <- factor(ncdf$weekday,levels = c("星期一", "星期二", "星期三", "星期四", "星期五", "星期六","星期日"))
	ncdf$rank <- as.factor(ncdf$rank)

  library(ggplot2)

		pg <- ggplot2::ggplot(ncdf,aes(x=date,y=AQI,color=rank)) +
			geom_point()+geom_smooth() + theme(text=element_text(family="STKaiti",size=14)) +
			scale_fill_discrete(breaks=c("优", "良","轻度污染","中度污染", "重度污染", "严重污染"))

		pgweek <- ggplot2::ggplot(ncdf,aes(x=date,y=AQI,color=rank)) +
			geom_point()+facet_grid(~weekday)+ theme(text=element_text(family="STKaiti",size=14))


	return(list(data=ncdf,plot=pg,pgweek = pgweek))

}
Gabegit/gmtools documentation built on May 6, 2019, 5:32 p.m.