上次跟大家分享的是首尾相连的路径图(从广州出发去上海,然后从上海去一趟南京,再从南京去一趟北京看天安门,看完天安门之后就回广州),今天来学习如何绘制以广州为起点的足迹图和热力图。
Heat Map from REmap.png一.广州为起点的足迹图
1.安装并加载包:
包的安装已经在前面的推文讲过,大家请参考https://mp.weixin.qq.com/s?__biz=MzIwMDIwNTIyNQ==&mid=2247484404&idx=1&sn=4e07ca750bde801aad2610c0601f189a&chksm=9681f532a1f67c248af30de46abe8dabcc5b945f88f06c50ed37f40214c6c9ed2f1e92305aac&token=800152865&lang=zh_CN#rd
library(REmap)#加载包
2.以广州为出发点,生成终点:
destination=c("shang hai","nan jing","bei jing","xi an","chong qing","wu han","liao ning","yin chuan","hang zhou","zun yi","shen zhen")
origin=rep("guang zhou",times=length(destination))#times=length(destination)这句是让广州重复11次,因为有11个终点
dat =data.frame(origin,destination)#将上面这两列数据存储在一个数据框里面
3.查看数据:
View(dat)
1.png
4.绘制:
remap(dat,title ="Travel",subtitle ="Chian")
广州起点.gif
关于参数与含义:
dat:数据集,每行数据表示从出发点到终点
title:标题
subtitle:副标题
二.热力图
city<-c("bei jing","shang hai","chong qing","xi an","wu han","liao ning")
heat<-c(0.09,0.2,0.05,0.2,0.9,0.15)#生成热度
temp <- get_geo_position(as.vector(city)) #获取每个城市的坐标
heatdata<-data.frame(temp$lon,temp$lat,heat)#生成包含经度,维度和热度的数据框
remapH(heatdata,minAlpha = 0.8,title = "Heat Map from REmap")
查看temp
2.png
查看heatdata
3.png
图形结果
Heat Map from REmap.png
欢迎关注我的公众号
R语言与SPSS学习笔记
网友评论