这是我的数据:
InitialLat InitialLong NewLat NewLong
62.46972 6.187194 51.4749 -0.221619
48.09750 16.310800 51.4882 -0.302621
我可以成对地将我的齿龈与地理圈库成对连接
(根据How Do I connect two coordinates with a line using Leaflet in R)
library(leaflet)
library(geosphere)
mydf <- data.frame(InitialLat = c(62.469722,48.0975), # initial df
InitialLong = c(6.187194, 16.3108),
NewLat = c(51.4749, 51.4882),
NewLong = c(-0.221619, -0.302621))
p1 <- as.matrix(mydf[,c(2,1)]) # it's important to list lng before lat here
p2 <- as.matrix(mydf[,c(4,3)]) # and here
gcIntermediate(p1, p2,
n=100,
addStartEnd=TRUE,
sp=TRUE) %>%
leaflet() %>%
addTiles() %>%
addPolylines()
如何添加标记?
我尝试了这个但没有成功:
library(tidyr)
markers <- mydf %>%
select(1, 2)
lines <- gcIntermediate (p1, p2,
n=100,
addStartEnd=TRUE,
sp=TRUE)
leaflet() %>%
addTiles() %>%
addPolylines(lines) %>%
addMarkers(markers, lat =~InitialLat, long =~InitialLong)
答案 0 :(得分:1)
您需要指定参数lines
和markers
是data
参数:
leaflet() %>%
addTiles() %>%
addPolylines(data = lines) %>%
addMarkers(data=markers,lat =~InitialLat, lng =~InitialLong)