使用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")
执行结果如下
原文地址:https://www.cnblogs.com/mxly/p/10155983.html
时间: 2024-10-15 20:51:59