REmap
A package for Echarts maps in R

REmap Tutorial

Links

Jul 22, 2015 - 简介与安装

REmap是一个基于Echarts http://echarts.baidu.com 的一个R包.主要的目的是为广大数据玩家提供一个简便的,可交互的地图数据可视化工具.目前托管在github, https://github.com/lchiffon/REmap

安装方式:

library(devtools)
install_github('lchiffon/REmap')
  • 提示:请使用Chrome或者Firefox来作为默认浏览器

其他信息

  • Version: 0.3
  • Authors@R: "Dawei Lang dawei.lang@supstat.com [aut, cre]"
  • Description: Provides an R interface to the JavaScript library ECharts for interactive map data visualization.
  • Depends: R (>= 3.1.2)
  • License: MIT + file LICENS

更新日志

V0.3

  • 修复remapC的warning bugs
  • 新增remapH热力图效果

V0.2.2

  • 调整demo的文档,可以用demo函数来调用
  • get_geo_postion把原始的机场经纬度chche改为城市经纬度
  • fix bugs

V0.2.1

  • 在调用remapC与remapB时,可以设置line和point的tooltip
  • 调用markPoint可以在数据中设置symbolSize来控制点的大小
  • 增加knitr的支持

V0.2

  • 增加分级统计图(Choropleth Map): remapC
  • 增加Bmap(百度地图与Echarts的结合): remapB
  • get_theme函数中增加三个新的控制变量
  • 格式化markLine和markPoint的使用
  • 删去了帮助文档的中文字符
  • 修正Windows用户下geo-cahce的问题(更快地获取地理信息)

V0.1

  • 基础函数: remap

Update Log

V0.3

  • fix warning bugs of remapC
  • add remapH heatmap function

V0.2.2

  • Support demo for REmap
  • Change the airport cache data to city data in get_geo_position function
  • Fix bugs

V0.2.1

  • Add tooltip to markpoint and markLine( set a vector called 'tooltip' to the data)
  • Add symbolSize to markpoint( set a vector called 'symbolsize' to the data)
  • Support REmap in knitr

V0.2

  • Add Choropleth Map into REmap: remapC
  • Add BaiduMap into REmap: remapB
  • Add three new control into get_theme
  • Add markLine,markPoint control
  • Delete Chinese character in .Rd file
  • Fix geo-cache system in windows

V0.1

  • Demo function: remap

Jul 21, 2015 - remap--入门的示例

REmap使用手册V0.1

REmap是一个基于Echarts http://echarts.baidu.com 的一个R包.主要的目的是为广大数据玩家提供一个简便的,可交互的地图数据可视化工具.目前托管在github, https://github.com/lchiffon/REmap

使用如下步骤安装:

library(devtools)
install_github('lchiffon/REmap')

目前V0.1提供的功能为百度迁徙的实现

提示:请使用Chrome或者Firefox来作为默认浏览器

最后要声明的一点:这个包并没有封装太多的参数,目的是简化使用和学习的流程,如果你想更深一步的修改这个可视化工具,请深入的学习Echarts!

Feature

  1. 使用Echarts封包,地图绘制使用的是SVG图形
  2. 采用百度API来自动获取城市的经纬度数据
  3. 支持Windows!

使用向导

获取经纬度

获取经纬度的函数是基于BaiduAPI的一个获取地理位置的功能.这个函数不仅是REmap下的一个功能,实际上,你也可以用它来抓取经纬度数据:

基本函数:

  • get_city_coord 获取一个城市的经纬度
  • get_geo_position 获取一个城市向量的经纬度
library(REmap)
city_vec = c("北京","Shanghai","广州")
get_city_coord("Shanghai")
[1] 121.47865 31.21562
get_geo_position (city_vec)
 lon lat city
1 116.6212 40.06107 北京
2 121.4786 31.21562 Shanghai
3 113.3094 23.39237 广州

注: windows用户会看到city一列为utf-8编码,可以使用get_geo_position (city_vec2)$city查看列向量的信息.(我能说我最好的建议是换Mac么?)

绘制迁徙地图

绘制地图使用的是主函数remap

remap(mapdata, title = "", subtitle = "", 
 theme =get_theme("Dark"))
  • mapdata 一个数据框对象,第一列为出发地点,第二列为到达地点
  • title 标题
  • subtitle 副标题
  • theme 控制生成地图的颜色,具体将会在get_theme部分说明
set.seed(125)
origin = rep("北京",10)
destination = c('上海','广州','大连','南宁','南昌',
 '拉萨','长春','包头','重庆','常州')
dat = data.frame(origin,destination)
out = remap(dat,title = "REmap实例数据",subtitle = "theme:Dark")
plot(out)
[フレーム]

该地图会写成一个html文件,保存在电脑里面,并通过浏览器打开该文件.以下的方式都可以看到这个地图:

## Method 1
remap(dat,title = "REmap实例数据",subtitle = "theme:Dark")
## Method 2 
out = remap(dat,title = "REmap实例数据",subtitle = "theme:Dark")
out
## Method 3
plot(out)

个性化地图

正如之前所说的,为了简化学习和使用的流程,REmap并没有封装太多的参数.(真的不是我懒)如果想更个性化地调整Echarts的参数,请移步Echarts的官方文档http://echarts.baidu.com/doc/doc.html

REmap中get_theme提供了迁徙地图中常用颜色的调整:

get_theme(theme = "Dark", lineColor = "Random",
 backgroundColor = "#1b1b1b", titleColor = "#fff",
 borderColor = "rgba(100,149,237,1)", regionColor = "#1b1b1b")
  • theme 默认主题,除了三个内置主题,可以使用"none"来自定义颜色
    • a character object in ("Dark","Bright,"Sky","none")
  • lineColor 线条颜色,默认随机,也可以使用固定颜色
    • Control the color of the line, "Random" for random color
  • backgroundColor 背景颜色
    • Control the color of the background
  • titleColor 标题颜色
    • Control the color of the title
  • borderColor 边界颜色(省与省之间的信息)
    • Control the color of the border
  • regionColor 区域颜色
    • Control the color of the region

颜色可以使用颜色名(比如’red’,’skyblue’等),RGB("#1b1b1b","#fff")或者一个rgba的形式("rgba(100,100,100,1)"),可以在这里找到颜色对照表.

  • 默认模板: Bright
## default theme:"Bright"
set.seed(125)
out = remap(dat,title = "REmap实例数据",subtitle = "theme:Bright",
 theme = get_theme("Bright"))
plot(out)
[フレーム]
  • 更改线条颜色
## set Line color as 'orange'
set.seed(125)
out = remap(dat,title = "REmap实例数据",subtitle = "theme:Bright",
 theme = get_theme("None",
 lineColor = "orange"))
plot(out)
[フレーム]
  • 更改其他颜色
## Set Region Color
out = remap(dat,title = "REmap实例数据",subtitle = "theme:Bright",
 theme = get_theme("None",
 lineColor = "orange",
 backgroundColor = "#FFC1C1",
 titleColor = "#1b1b1b",
 regionColor = '#ADD8E6'))
plot(out)
[フレーム]

AltStyle によって変換されたページ (->オリジナル) /

Jul 10, 2015 - remapC--分级统计图

remapC--分级统计图

REmap是一个基于Echarts http://echarts.baidu.com 的一个R包.主要的目的是为广大数据玩家提供一个简便的,可交互的地图数据可视化工具.目前托管在github, https://github.com/lchiffon/REmap

remapC

remapC是用于创建分级统计图(Choropleth map).即根据子区域数值的多少进行深浅不同的颜色填充的地图形式.目前支持的地图为:

  1. ‘china’ 中国省份地图
  2. ‘world’ 世界地图
  3. 各省市地图,如’广东’,’西藏’等...

熟悉R中绘制Choropleth map的同学可能清楚,基本的绘图包maps支持基本的地图绘制,但是缺点是绘制中国地图中是没有重庆的(版本较旧),所以有使用shp文件来绘制的方式

remapC的使用

函数的调用形式为:

remapC(data,
 maptype = 'china',
 color = c('#1e90ff','#f0ffff'),
 theme = get_theme("Bright"),
 title = "",
 subtitle = "",
 mindata = NA,
 maxdata = NA,
 # mark Line & point
 markLineData = NA,
 markPointData = NA,
 markLineTheme = markLineControl(),
 markPointTheme = markPointControl(),
 geoData = NA)

参数看起来很多,这里仅描述前几个参数,后面的markLine与markPoint是用于在绘制好的地图上添加标线和标点的,会在remapB中详细介绍,remapC中重要的参数有:

  • data: 数据框,第一列为子区域名(比如全国地图的省名,省级地图的市名)
  • color: 传入单个颜色就使用从白色到该色的填充,多个颜色根据值大小计算填充颜色
  • maptype: 地图的格式,’china’代表中地图,’world’代表世界地图

用示例数据chinaIphone来做演示:

head(chinaIphone)
 V1 V2
1 北京 629
2 天津 516
3 上海 280
4 重庆 933
5 河北 296
6 河南 172
remapC(chinaIphone)

更改color参数来调整颜色:

remapC(chinaIphone,
 color = 'orange')
## 颜色改为白色到橘红色
remapC(chinaIphone,
 color = c('orange','red'))
## 颜色改为红色到橘红色

此外,使用mapType参数可以改变地图的类型,绘制子地图或者世界地图:

data = data.frame(country = mapNames("world"),
 value = 5*sample(178)+200)
head(data)
remapC(data,maptype = "world",color = 'skyblue')

其中mapNames()函数可以得到某个地图下的子图信息:

mapNames('西藏')
[1] "那曲地区" "阿里地区" "日喀则地区" "林芝地区" 
[5] "昌都地区" "山南地区" "拉萨市" 
data = data.frame(country = mapNames('西藏'),
 value = 50*sample(7)+200)
head(data)
remapC(data,maptype = '西藏',color = 'skyblue')

其他的参数: - theme: 地图的主题,里面可以设置背景颜色,标题颜色,边界颜色等 - title,subtitle: 标题与附标题 - max,min: dataRange的最大最小值

比如,精细的调整一下最初的地图:

remapC(chinaIphone,
 title = "remapC实例地图",
 theme = get_theme('none',backgroundColor = '#fff',
 titleColor = "#1b1b1b",
 pointShow = T),
 max = 2000)

最后,再演示下remapC中使用markLine和markPoint的效果:

remapC(chinaIphone,
 title = "remapC实例地图",
 theme = get_theme('none',backgroundColor = '#fff',
 titleColor = "#1b1b1b",
 pointShow = T),
 max = 2000,
 markLineData = demoC,
 markPointData = demoC[,2])
Page: 1 of 2 Older

©2016 REmap. Powered by Jekyll, theme by Scott Emmons under Creative Commons Attribution