Leaflet addPolylines 没有绘制数据对象的所有值(或线)

Leaflet addPolylines is not plotting all values (or lines) of a data object

我正在使用 addPolylinesleaflet 生成的网络地图上叠加特定值的等高线,但是,addPolylines 并未绘制它所绘制的所有数据随附。根据第一张图片,至少有两个 125 值的区域是明显的,但传单生成的地图仅显示一个区域。
数据可以从here下载,为addPolylinesleaflet生成SpatialLinesDataFrame对象的可重现脚本生成的地图如下:

rm(list=ls())
library(leaflet)
library(maptools)

# create a vector of lon, lat, and read data
lon1 <- seq(-124.938,length=59,by=1)
lat1 <- seq(25.063,length=29,by=1)
data1 <- matrix(scan(file="AnnualPrcpValues.txt"),ncol=length(lat1),byrow = T)

## spatial pattern of precipitation
## I choose a value *125* correspond to light yellow color to plot contours on leaflet generated map
## at least two regions corresponds to this value, i.e., Pacific northwest & Southwest region] 
filled.contour(lon1,lat1,data1,color=terrain.colors)

## The following code calculates contour lines correspond to a value *125*
## and then converts contour lines into a SpatialLinesDataFrame object

CL=contourLines(lon1,lat1,data1,levels=c(125))
c.linesSP <- ContourLines2SLDF(CL)

c.linesSP 具有三条线的坐标,但是,addPolylines 仅绘制一个区域的等高线

str(coordinates(c.linesSP))

##List of 1
## $ :List of 3
##  ..$ : num [1:17, 1:2] -123 -122 -122 -122 -122 ...
##  ..$ : num [1:5, 1:2] -125 -124 -123 -124 -125 ...
##  ..$ : num [1:9, 1:2] -86.4 -86.9 -87.9 -88.9 -89.9 ...


## leaflet generated map
map1 <- leaflet() %>% addTiles() %>% 
   setView(lng = -80, lat = 40, zoom = 2)
map2<- map1 %>% addPolylines(data=c.linesSP,color="red")

## It should have three lines, but only one line is seen in the Pacific Northwest region
map2

## However, contour line in the southwest region is plotted when explicilty co-ordinates, i.e., [[1]] [[3]] are supplied
## 
tempdata <- coordinates(c.linesSP)[[1]][[3]]
map2 %>% addPolylines(tempdata[,1],tempdata[,2],
                         weight=1.25,color="green") %>%
   addMarkers(tempdata[,1],tempdata[,2])

不清楚为什么 addPolylines 没有绘制它最初提供的所有坐标。非常感谢建议。

通过 devtools::install_github("rstudio/leaflet") 从 github 更新到最新的 leaflet 版本应该可以解决您的问题。这是我的 sessionInfo(),您的代码运行良好,我看到 3 行:

R version 3.3.2 (2016-10-31)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: Ubuntu 14.04.5 LTS

locale:
 [1] LC_CTYPE=en_US.UTF-8       LC_NUMERIC=C               LC_TIME=de_DE.UTF-8       
 [4] LC_COLLATE=en_US.UTF-8     LC_MONETARY=de_DE.UTF-8    LC_MESSAGES=en_US.UTF-8   
 [7] LC_PAPER=de_DE.UTF-8       LC_NAME=C                  LC_ADDRESS=C              
[10] LC_TELEPHONE=C             LC_MEASUREMENT=de_DE.UTF-8 LC_IDENTIFICATION=C       

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
[1] maptools_0.8-39    sp_1.2-3           leaflet_1.0.2.9010

loaded via a namespace (and not attached):
 [1] Rcpp_0.12.8     magrittr_1.5    devtools_1.12.0 xtable_1.8-2    lattice_0.20-34 R6_2.2.0       
 [7] httr_1.2.1      tools_3.3.2     grid_3.3.2      git2r_0.15.0    withr_1.0.2     htmltools_0.3.5
[13] crosstalk_1.0.0 yaml_2.1.14     digest_0.6.10   shiny_0.14.2    htmlwidgets_0.8 curl_2.1       
[19] memoise_1.0.0   mime_0.5        jsonlite_1.1    httpuv_1.3.3    foreign_0.8-67