简体   繁体   English

R小叶:绘制折线时线丢失

[英]R Leaflet: lines missing when plotting polylines

I have a pretty simple spatial object composed of a bunch of lines. 我有一个由一串线组成的非常简单的空间对象。 I can plot it in different ways with no problems: QGIS, mapshaper.org. 我可以用不同的方式绘制它,而不会出现问题:QGIS,mapshaper.org。 Even the standard R plot() function: 甚至是标准的R plot()函数:

这个情节还可以

But when I plot it with leaflet() , some segments mysteriously disappear, leaving disconnected lines behind: 但是,当我使用leaflet()对其进行绘制时,某些段神秘地消失了,从而留下了断开连接的线:

在此处输入图片说明

A reproducible example follows. 下面是一个可重现的示例。 NOTE: I use a GeoJSON source file for simplicity here. 注意:为了简单起见,我使用GeoJSON源文件。 I have also tried saving the lines as an ESRI shapefile, with the same effect: The data is plotted OK with QGIS, or plot() , etc but not with leaflet() . 我还尝试过将线另存为ESRI shapefile,具有相同的效果:可以使用QGIS或plot()等对数据进行绘制,但不能使用leaflet() plot()

library(leaflet)
library(rgdal)

download.file("https://www.dropbox.com/s/nij2oa2rp7ijaaj/commuter_rail.geojson?dl=1",
                           method = "auto", mode = "wb", destfile = "commuter_rail.json")
commuterLines <- readOGR("commuter_rail.json",
                         "OGRGeoJSON")

# Straight R Plot - Looks good
plot(commuterLines)

# Plot using leaflet - Some lines are missing!

leaflet() %>% addPolylines(data = commuterLines)

UPDATE: 更新:

Here's the reproducible example running as a shiny app, hosted at shinyapps.io, and showing the weird leaflet behavior: https://havb.shinyapps.io/leaflet_example/ 这是可重复运行的示例,运行在shinyapps.io上,作为一个闪亮的应用程序运行,并显示了奇怪的传单行为: https ://havb.shinyapps.io/leaflet_example/

UPDATE: the problem seems to be a bug in an older version of the leaflet package available from CRAN. 更新:问题似乎是CRAN提供的旧版传单包中的错误。 Installing the latest development version from Github resolves the issue. 从Github安装最新的开发版本可以解决此问题。

I don't have enough rep to comment, but I tried your code and it worked for me: 我没有足够的代表评论,但我尝试了您的代码,它对我有用:

在此处输入图片说明

Perhaps it has something to do with your local configuration? 也许这与您的本地配置有关? Have you tried reinstalling the leaflet package? 您是否尝试过重新安装传单包?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM