[LR]用R绘制上海地铁

使用Leaflet绘制上海地铁地图

直接上代码,如下:

library(leaflet)library(data.table)## 数据存放在_rmd/data中,坐标数据分GPS坐标、Google坐标和百度坐标。stations % setView(lng = 121.468888888889, lat = 31.2358333333333, zoom = 10) %>% addTiles() # 暂时没研究出如何画多个线条,先通过循环绘制# 发现7号线的场中路经纬度有问题,修复# 发现11号线的兆丰路、光明路、花桥、龙华路经纬度有问题,修复# 发现12东兰路经纬度有问题,修复for(line in unique(stations[,2])){  line_length %      addPolylines(lat=stations[stations$line==line,4],lng=stations[stations$line==line,5],color=lines_color[line,2])    Shanghai %      addPolylines(lat=stations[stations$line==line,4][c(1,line_length)],lng=stations[stations$line==line,5][c(1,line_length)],color=lines_color[line,2])  }else if(line==10){    # 由于10号线在龙溪路站以后分为两条线路,需分两端绘制    Shanghai %      addPolylines(lat=stations[stations$line==line,4][c(1:(line_length-3))],lng=stations[stations$line==line,5][c(1:(line_length-3))],color=lines_color[line,2])    Shanghai %      addPolylines(lat=stations[stations$line==line,4][c(24,(line_length-2):line_length)],lng=stations[stations$line==line,5][c(24,(line_length-2):line_length)],color=lines_color[line,2])  }else if(line==11){    # 由于11号线在嘉定新城站以后分为两条线路,需分两端绘制    Shanghai %      addPolylines(lat=stations[stations$line==line,4][c(1:(line_length-7))],lng=stations[stations$line==line,5][c(1:(line_length-7))],color=lines_color[line,2])    Shanghai %      addPolylines(lat=stations[stations$line==line,4][c(28,(line_length-6):line_length)],lng=stations[stations$line==line,5][c(28,(line_length-6):line_length)],color=lines_color[line,2])  }else{    Shanghai %      addPolylines(lat=stations[stations$line==line,4],lng=stations[stations$line==line,5],color=lines_color[lines_color$line==line,2])  }}# 添加地铁站名Shanghai %  addProviderTiles("CartoDB.Positron") %>%   addCircleMarkers(stations$gps_lon, stations$gps_lat, popup =stations$station,color = pal(stations$line), radius=1.5) %>%  addLegend(pal=pal,values = stations$line)Shanghai

其他问题

上传Github搭建的rmarkdown博客时,报错如下错误,不能生存图片。

PhantomJS not found. You can install it with webshot::install_phantomjs(). If it is installed, please make sure the phantomjs executable can be found via the PATH variable.

按照提示运行webshot::install_phantomjs(),能够生成了图片,但是生成的图片为静态图,不是leaflet的交互图,以后再查询解决吧。

关键字:r


本文来自互联网用户投稿,文章观点仅代表作者本人,不代表本站立场,不承担相关法律责任。如若转载,请注明出处。 如若内容造成侵权/违法违规/事实不符,请点击【内容举报】进行投诉反馈!

相关文章

立即
投稿

微信公众账号

微信扫一扫加关注

返回
顶部