首页 > 解决方案 > 如何防止R中Leaflet中的标签重叠?

问题描述

我一直在努力寻找标签不重叠的解决方案。请参考图片。有什么建议么?

地图

可重现的代码:

gyms <- 
structure(list(gym = c("Ashburton Pool and Recreation Centre", 
                       "Brunswick Baths", "Casey Aquatic and Recreation Centre", "Hawthorn Aquatic & Leisure Centre", 
                       "Macleod Recreation & Fitness Centre", "Northcote Aquatic & Recreation Centre", 
                       "RecWest Footscray", "Aquahub", "Knox Leisureworks", "Waves Leisure Centre"
), suburb = c("Ashburton", "Brunswick", "Narre Warren", "Hawthorn", 
              "Macleod", "Northcote", "West Footscray", "Croydon", "Boronia", 
              "Highett"), lat = c(-37.8664, -37.77111, -38.02074, -37.82054, 
                                  -37.72407, -37.76906, -37.7946, -37.80099, -37.85752, -37.95049
              ), long = c(145.08518, 144.96023, 145.29975, 145.03313, 145.06882, 
                          145.01182, 144.87968, 145.28072, 145.27868, 145.05513)), row.names = c(NA, 
                                                                                                 -10L), class = c("tbl_df", "tbl", "data.frame"))


library(leaflet)


leaflet() %>% 
  addTiles() %>% 
  
  addMarkers(lng = gyms$long, lat = gyms$lat, 
             label = gyms$suburb,
             labelOptions = labelOptions(noHide = T, direction = 'auto')
             , options = markerOptions(riseOnHover = T),
             group = "gyms")

标签: rleaflet

解决方案


推荐阅读