这是我的代码
library(leaflet)
library(dplyr)
df <- data.frame(lat = c(44.7,44.7,44.7,44.2,44.5,45.0),lon = c(-63.4,-63.4,-63.4,-64,-63.1,-62.8),id = c(0,0,0,1,1,1))
leaflet() %>%
addTiles() %>%
addPolylines(data = df,lng = ~lon, lat = ~lat, group = ~id)
我想要发生的是让3条线都指向该位置(44.7,-63.4),但我无法弄清楚如何实现它。
非常感谢你的帮助
答案 0 :(得分:2)
如果使用点对创建id,则可以使用dplyr::arrange
:
library(leaflet)
library(dplyr)
df <- data.frame(lat = c(44.7,44.7,44.7,44.2,44.5,45.0),
lon = c(-63.4,-63.4,-63.4,-64,-63.1,-62.8),
id = rep(1:3))
df %>% arrange(id) %>% leaflet %>%
addPolylines(lng = ~lon, lat = ~lat)