R实现pm2.5地图数据展示

使用rvest包抓取pm2.5静态页面数据,使用leafletCN包实现pm2.5数据的地图展示,代码如下所示:

library(rvest)
library(leafletCN)
Sys.setlocale("LC_CTYPE","eng")
doc = read_html("http://www.pm25s.com/cn/rank/")
cities = doc %>% html_nodes(".cityrank a") %>%
  html_text()
AQI = doc %>% html_nodes("span[class^='lv']") %>%
  html_text() %>% .[c(F,F,T)] %>% as.numeric
dat = data.frame(city=cities,AQI=AQI)
dat
geojsonMap(dat,"city",
           popup = paste0(dat$city,":",dat$AQI),
           palette = "Reds",legendTitle = "AQI")

执行结果如下

 

posted @ 2018-12-21 15:26  Luis Yang  阅读(944)  评论(0编辑  收藏  举报