生成された Web マップにaddPolylines
特定の値の等高線をオーバーレイするために使用していますが、提供されているすべてのデータをプロットしているわけではありません。最初の画像のように、値が125の少なくとも 2 つの領域が明らかですが、リーフレットで生成されたマップには 1 つの領域しか表示されません。データはここからダウンロードでき、SpatialLinesDataFrame オブジェクトを生成する再現可能なスクリプトと、次のようにマップを生成できます。leaflet
addPolylines
addPolylines
leaflet
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
3 本の線の座標がありますが、addPolylines
1 つの領域のみの等高線をプロットします
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
最初に提供されたすべての座標をプロットしない理由は明らかではありません。提案を大歓迎します。