REmap是一个基于Echarts http://echarts.baidu.com 的一个R包.主要的目的是为广大数据玩家提供一个简便的,可交互的地图数据可视化工具.目前托管在github, https://github.com/lchiffon/REmap
安装方式:
library(devtools)
install_github('lchiffon/REmap')
get_geo_postion把原始的机场经纬度chche改为城市经纬度get_geo_position functionREmap是一个基于Echarts http://echarts.baidu.com 的一个R包.主要的目的是为广大数据玩家提供一个简便的,可交互的地图数据可视化工具.目前托管在github, https://github.com/lchiffon/REmap
使用如下步骤安装:
library(devtools)
install_github('lchiffon/REmap')
目前V0.1提供的功能为百度迁徙的实现
提示:请使用Chrome或者Firefox来作为默认浏览器
最后要声明的一点:这个包并没有封装太多的参数,目的是简化使用和学习的流程,如果你想更深一步的修改这个可视化工具,请深入的学习Echarts!
获取经纬度的函数是基于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"来自定义颜色
lineColor 线条颜色,默认随机,也可以使用固定颜色
backgroundColor 背景颜色
titleColor 标题颜色
borderColor 边界颜色(省与省之间的信息)
regionColor 区域颜色
颜色可以使用颜色名(比如’red’,’skyblue’等),RGB("#1b1b1b","#fff")或者一个rgba的形式("rgba(100,100,100,1)"),可以在这里找到颜色对照表.
## 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)
[フレーム]
REmap是一个基于Echarts http://echarts.baidu.com 的一个R包.主要的目的是为广大数据玩家提供一个简便的,可交互的地图数据可视化工具.目前托管在github, https://github.com/lchiffon/REmap
remapC是用于创建分级统计图(Choropleth map).即根据子区域数值的多少进行深浅不同的颜色填充的地图形式.目前支持的地图为:
熟悉R中绘制Choropleth map的同学可能清楚,基本的绘图包maps支持基本的地图绘制,但是缺点是绘制中国地图中是没有重庆的(版本较旧),所以有使用shp文件来绘制的方式
函数的调用形式为:
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中重要的参数有:
用示例数据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])
©2016 REmap. Powered by Jekyll, theme by Scott Emmons under Creative Commons Attribution