Last active
February 5, 2020 09:40
-
-
Save TerenceLiu98/68f3135f58c1b3b15130b85ad86f6760 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ## Author: Terence Liu | |
| ## Date: 2020-02-05 | |
| ## Follow: CC0 | |
| require(jsonlite) | |
| require(ggplot2) | |
| require(maptools) | |
| require(maps) | |
| require(mapdata) | |
| library(devtools) # install.packages("devtools", dep = T, repos = "https://mirrors.tuna.tsinghua.edu.cn/CRAN/") | |
| install_github('lchiffon/REmap') | |
| library(REmap) | |
| url = 'https://ncov.html5.qq.com/api/getCommunity?province=' | |
| x <- readLines(url, encoding = "UTF-8") | |
| x <- sub("^\\d+", "", x) | |
| x <- sub("^\\(", "", x) | |
| x <- sub("\\)$", "", x) | |
| y <- fromJSON(x) | |
| nCoV_data_position <- y$community | |
| # Here is an example: | |
| head(nCoV_data_position$广东省$深圳市$南山区) | |
| name <- nCoV_data_position$广东省$深圳市$南山区[6] | |
| lng <- nCoV_data_position$广东省$深圳市$南山区[17] | |
| lat <- nCoV_data_position$广东省$深圳市$南山区[18] | |
| shenzhen_nanshan <- data.frame(name, lng, lat) | |
| # using Baidu Map's API | |
| options(remap.ak = "Ti0LKVEqqTK5pcB6peXXXXXXXXXXXXXXXXXXV") | |
| # using remap to plot map | |
| remapB(markPointData = data.frame(shenzhen_nanshan$community), | |
| geoData = shenzhen_nanshan, | |
| markPointTheme = markPointControl(effect = F,symbol = "pin", | |
| symbolSize = 5, | |
| color="red"), | |
| title="深圳南山疫情分布") | |
| # example pic | |
| # <a href="https://sm.ms/image/7WndTa4lHtbxIDJ" target="_blank"><img src="https://i.loli.net/2020/02/05/7WndTa4lHtbxIDJ.png" ></a> | |
| # Reference: | |
| # https://mp.weixin.qq.com/s/lrQWGKj-mReWrxfi_4Sw9A | |
| # https://zhuanlan.zhihu.com/p/37492683 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment