Skip to content
Prev 257674 / 398502 Next

Sorting values within a raster

On Apr 21, 2011, at 3:23 PM, Sara Maxwell wrote:

            
?quantile
> quantile(values(r), prob=seq(0,1,by=0.1))
          0%         10%         20%         30%         40%
0.004888148 0.106378528 0.217009097 0.307201289 0.364990984
         50%         60%         70%         80%         90%
0.512523817 0.593382875 0.667916094 0.722919876 0.835839832
        100%
0.996683575

You will also need findInterval()

If you want to create a factor that will assign your colors. perhaps  
this could be used to index a suitable color vector:

fac <- findInterval(values(r), quantile(values(r),  
prob=seq(0,1,by=0.1)) )
 > fac
   [1]  6 10  1 10  7  7  8 10  2  9  9  1  6  2  9  1  9  4  2  2
  [21]  3  4  8  9  7  1  9  2 10  5  4  9  8  1  8 10  1 11  3  5
  [41]  5  6  6  5  6  7  4  7  5  3  8  6  3  4 10  4  7  7  8  9
  [61] 10  4  1  8  8  8  3  7  5  1  9  5  2  7  2 10  3  8  4  9
  [81]  6  6  2  6 10  5  5  4  3  6  2  2  1  3  3  3  4  7  1  5

David Winsemius, MD
West Hartford, CT