这是我的数据:
InitialLat InitialLong NewLat NewLong
62.46972 6.187194 51.4749 -0.221619
48.09750 16.310800 51.4882 -0.302621
我可以将传单中的坐标与 geosphere 库成对连接
(根据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)