Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

REmap::remapC():Error in if (markLineLogi & markPointLogi & !geoDataLogi) { : the condition has length > 1 #1

Open
englianhu opened this issue Sep 30, 2022 · 1 comment

Comments

@englianhu
Copy link
Owner

englianhu commented Sep 30, 2022

原著:

由于百度地图自从前几年开始只限制中国同胞注册为百度开发人员才能使用,导致无法正常使用。故此尝试修改全球地图数据来源,而且目前正在科研高频量化对冲交易论文内容、函数、代码都一律汉化,所以尝试将此REmap原版(原著:郎大为http://langdawei.com) ,稍微修改一下为REmap程序包中文版(百度绘图),也是第一个使用中文编程的R语言程序包。

  • 英文地名使用maps::world.cities程序包内数据即可。
  • 而中文数据可以使用maps::world.cities程序包内数据已加工并储存在REmap程序包的附属数据地图数据.csv
## Load REmap package
## https://github.com/Lchiffon/REmap
require('REmap')

## Reinitialized the REmap setting
suppressAll(remap.init())

## Get world city geocode from simplemaps.com
## https://simplemaps.com/data/world-cities
geodata <- maps::world.cities |> 
  dplyr::rename(city = name, country = country.etc, lon = long) |> 
  dplyr::select(country, city, capital, lon, lat, pop) |> 
  dplyr::filter(city %in% c('Zhengzhou', 'Kuala Selangor', 
                            'Tanjong Karang', 'Klang', 'Seri Kembangan', 
                            'Serdang', 'Equine Park') | capital != 0)

countries <- geodata$country |> 
  unique()

## randomly set country codes
data <- data.frame(
  country = countries, 
  value = 5 * sample(length(countries)) + 200)

## cities
vec <- geodata$city

## lon & lat of cities
geodata <- geodata |> 
  data.frame() |> 
  dplyr::select(lon, lat, city) |> 
  dplyr::rename(vec = city)

## Design a line data frame
markLinedata <- data.frame(
  origin = rep('Zhengzhou', (length(vec) - 1)), 
  destination = geodata$vec[!geodata$vec %in% 'Zhengzhou'])

以下数据经过翻译并储存,读取后即可使用。

## 读取从maps::world.cities程序包翻译并储存中文地名文件
#source('文艺数据库/geoname.R')
经纬度 <- read_csv('文艺数据库/地图数据.csv', show_col_types = FALSE)

诸国 <- 经纬度$国家 |> 
  unique()

## 随即设置区域号
随机国号 <- data.frame(
  国家 = 诸国, 
  国号 = 5 * sample(length(诸国)) + 200)

## 城镇矢量
诸城镇 <- 经纬度$城镇

## 城镇经纬度
经纬度 <- 经纬度 |> 
  dplyr::select(经度, 纬度, 城镇) #因为呈现出来的夜光导航图只显示地名和随机国号,故此文件名、纬经度并无翻译为繁体

## 描画彩色霓虹导航线
夜光导航线 <- data.frame(
  出发点 = rep('郑州市', (nrow(经纬度) - 1)), 
  抵达点 = 经纬度$城镇[!经纬度$城镇 %in% '郑州市'])
## 绘制 REmap 夜光导航图 
夜光导航图 <- remapC(随机国号, maptype = 'world', 
               color = c('black', 'black'),
               theme = get_theme(backgroundColor = 'black'), 
               title = '量化圈', subtitle = '金融计量经济学', 
               markPointData = 诸城镇, markLineData = 夜光导航线, 
               geoData = 经纬度)
knitrREmap(夜光导航图, local = FALSE)
#Error in if (markLineLogi & markPointLogi & !geoDataLogi) { : the condition has length > 1

Screenshot_20220930_210200

个人简历中,尝试导入中文地图数据,使用以上原版REmap::remapC()

@englianhu
Copy link
Owner Author

englianhu commented Jun 12, 2023

秦谏上奏

以下网站提供离线地图数据,可以嵌入程序包。

众卿商议

最优方案

相关奏折

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant