簡體   English   中英

傳單addPolylines並未繪制數據對象的所有值(或線)

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

我正在使用addPolylinesleaflet生成的網絡地圖上覆蓋特定值的輪廓,但是, addPolylines並未繪制提供的所有數據。 根據第一張圖片,至少有兩個值為125的區域是明顯的,但傳單生成的地圖僅顯示一個區域。
可以從此處下載數據,該腳本是可重現的腳本,該腳本為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

一條輪廓線的WebMap

## 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])

帶有兩條輪廓線的Webmap

目前尚不清楚為什么addPolylines不會繪制其最初提供的所有坐標。 非常感謝您的建議。

通過devtools::install_github("rstudio/leaflet")從github更新到最新的傳單版本應該可以解決您的問題。 這是我的sessionInfo() ,您的代碼可以很好地運行,我看到三行:

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 

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM