admin管理员组文章数量:1312979
I have a leaflet map (in a R Shiny application) with multiple circles/radii added as the centroid of a province.
What I would like to do is to slightly offset the circles/radii so they are not totally overlapping. Is there a way to do this? Ideally, I don't want to mess with the longitudes and latitudes, and would rather apply some overall offsetting factor. I could not find an option for this here, .pdf.
Example code:
library(leaflet)
# added 2 markers for Delhi, India
leaflet() %>%
addTiles() %>%
addCircles(lng=77.1025, lat=28.7041,
popup="Delhi, India", color="blue") %>%
addCircles(lng=77.1025, lat=28.7041, # can this second radius be offset somehow?
popup="Delhi, India", color="red")
I have a leaflet map (in a R Shiny application) with multiple circles/radii added as the centroid of a province.
What I would like to do is to slightly offset the circles/radii so they are not totally overlapping. Is there a way to do this? Ideally, I don't want to mess with the longitudes and latitudes, and would rather apply some overall offsetting factor. I could not find an option for this here, https://cran.r-project./web/packages/leaflet/leaflet.pdf.
Example code:
library(leaflet)
# added 2 markers for Delhi, India
leaflet() %>%
addTiles() %>%
addCircles(lng=77.1025, lat=28.7041,
popup="Delhi, India", color="blue") %>%
addCircles(lng=77.1025, lat=28.7041, # can this second radius be offset somehow?
popup="Delhi, India", color="red")
Share
Improve this question
edited Jan 31 at 17:55
Jan
9,4786 gold badges20 silver badges33 bronze badges
asked Jan 31 at 17:47
rratnayarratnaya
213 bronze badges
1 Answer
Reset to default 2I'd still consider some added jitter to be one of the easiest methods, especially when layer data is kept in a frame:
library(leaflet)
library(dplyr, warn.conflicts = FALSE)
circles <- tribble(
~lng, ~lat, ~popup, ~color,
77.1025, 28.7041, "Delhi, India", "blue",
77.1025, 28.7041, "Delhi, India", "red"
)
leaflet() %>%
addTiles() %>%
addCircles(
lng = ~lng, lat = ~lat,
popup = ~popup, color = ~color,
data = mutate(circles, across(lng:lat, \(x) jitter(x, amount = 5e-5)))
)
Or perhaps opt for clustered CircleMarkers instead:
leaflet() %>%
addTiles() %>%
addCircleMarkers(
lng = ~lng, lat = ~lat,
label = ~popup, popup = ~popup, color = ~color,
clusterOptions = markerClusterOptions(),
data = circles
)
本文标签: rOffset circlesradii produced by addCirclesStack Overflow
版权声明:本文标题:r - Offset circlesradii produced by addCircles - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741901896a2403916.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论