1

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

www
  • 38,575
  • 12
  • 48
  • 84
Carlos
  • 103
  • 1
  • 11
  • try `findinterval` in base R and see this thread: https://stackoverflow.com/questions/46046236/map-numerics-to-categorical-values-in-r-based-on-different-ranges-for-the-numer – Rich Pauloo Sep 05 '17 at 03:12

1 Answers1

0
 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.

Rich Pauloo
  • 7,734
  • 4
  • 37
  • 69