我正在寻找使用R函数leaflet :: addMarkers时重叠标签的修复方法。
long <- c(147.768, 147.768, 147.768,147.768, 147.768, 147.768)
lat <- c(-36.852, -36.852, -36.852,-36.852, -36.852, -36.852)
label <- c('long label1', 'long label2', 'long label3','long label4', 'long label5', 'long label6')
markers <- data.frame(lat,long,label)
leaflet() %>%
addTiles() %>% # Add default OpenStreetMap map tiles
addMarkers(lng=markers$long, lat= markers$lat,
popup="The birthplace of R",
label = markers$label,
labelOptions = labelOptions(noHide = T, direction = 'auto'),
clusterOptions = markerClusterOptions()
)
Run Code Online (Sandbox Code Playgroud) 我的数据行具有重复的纬度/经度,并且我想包含一个包含所有分组列数据的标签。
# Make sample dataframe
long <- c(147.5, 147.5, 147.5, 147, 147)
lat <- c(-36.5, -36.5, -36.5, -36, -36)
label <- c(1, 1, 2, 1, 2)
markers <- data.frame(lat,long,label)
# Combine labels based on lat long
markers <- markers %>%
group_by(lat, long) %>%
summarize(concat_label = toString(label))
# Markers with all of the labels
leaflet() %>%
addTiles() %>%
addMarkers(lng=markers$long, lat= markers$lat,
popup= markers$concat_label
)
Run Code Online (Sandbox Code Playgroud)
toString 是否有一个版本使用换行符而不是逗号?我尝试使用paste和paste0但无法让它工作。