Leaflet addCircleMarkers radius on R

1.6k views Asked by At

I have a "problem" with radius in leaflet addCircleMarkes

example dataset:

lat    long    number
 -      -        4
 -      -        26
 -      -        13
 -      -        40
 -      -        30

i change the radius of circle markers in map with radius = ~ifelse(data$number <=25, 2, ifelse((data$number > 25 & data$number <=50),4,6)) (nested if) not problem with that, but i think there is another more "elegant" way.

I can't figure out how automatically generate a range of numbers, for example [0-25] = 2, [26 - 50] = 4 and [51 - more] = 6 and compare:

if data$number is in specific range put in radius the number associate to that range.

The original dataset have numbers between 1 and 1500 so my actually form it does not help too much.

Thanks in advance

1

There are 1 answers

1
Rich Pauloo On BEST ANSWER
 radius <- findInterval(exampledataset$number,c(25,50,1500)) * 2

Add this as a column onto your SpatialPointsDataFrame, then assign it as the radius in leaflet.