Thursday, June 04, 2015

Color/colour band combination generator in R

Last time I did color band combinations I made a spreadsheet in Excel.  This time around I wrote a quick R script that generates the combos much more efficiently.  There is a SAS program available to generate color band combinations as well.  I've never tried it, but if you have more complex needs and SAS is available to you it looks great.  We just needed two colors on one leg so my R script does just as nicely for the simpler case.

#Color key:

           "O","R","W","Y", "L")

#load library (install it first if you don't already have it; I hadn't used 'gtools' before).
#get all permutations
#n= number of colors, r=how many are adjacent, v= the vector of colors
#I allow repeats because I'm okay with two colors together (yellow over yellow, for example).

#count how many combinations you've made.

write.csv(bandcombos, file="yourproject_bandcombos.csv")
#Take your file and you can open it in a spreadsheet program or wherever for further formatting/use.
#We specified our bands would go on the left leg, so you could reuse all these combinations
#for the right leg.


  1. Great resource, thanks so much!

  2. Hi Claire! Awesome, so glad I googled "get bird banding combinations easily"!

    1. Hi Leanne, glad it's helpful! I hope your project is going well.

  3. Hi Claire,

    Thanks so much for posting this! We just added a new color and need to redo our combination list. We use two bands on each leg, one of which is the aluminum band. Is there a way to make every color repeat except aluminum?


    1. The way I've done this in the past is to consider aluminum a "fixed" position and not include it in the list of colors. So for two bands per leg (three positions with color and one as aluminum), I generate the rest relative to a fixed aluminum position. So I'd use the three-color combo list four times (manually shifting where the aluminum band is at bottom left, bottom right, top left, and top right after generating the color combinations). I will look into a way to do it with the code too, though, and post a new update when I get it going.

  4. Thanks Claire! I'll try that, and I'll look for your update.


Comments and suggestions welcome.