title: Transparent equivalent of given color
body: <p>I've had this a few times, so here goes: I'm making some plots which hold curves with estimates of a parameter given a tuning parameter.</p>
  
  <p>Typically, I also have SDs for each estimated value, so I could show error bars around each of them.</p>
  
  <p>However, I don't like error bars, and would prefer some smoothed version of it. This is in itself no problem (ie I know how to do this). However, my plot contains several of these similar curves, each one in its own color. So I would like to add the 'smoothed errorregion' to each curve in a color that matches the color of the curve itself. Of course, I would like to do this somewhat transparently, so I can still see the other curves through the 'error region'.</p>
  
  <p>So, my question is: given a color (specified by either a number, a name or an rgb value --- note the first two pose an extra problem, but this is occurring rather often, as the basic plotting functions take these as valid color values), how can I find find the matching color that has the same rgb but a different (given) alpha level (transparency). I would like a function like:</p>
  
  <pre><code>makeTransparent&lt;-function(someColor, alpha=100)
  {
    newColor&lt;-someColor + alpha #I wish
    return(newColor)
  }
  </code></pre>
  
  <p>This should work for things like:</p>
  
  <pre><code>makeTransparent(2)
  makeTransparent("red")
  makeTransparent(rgb(0,0,1))
  </code></pre>
  
  <p><strong>Edit</strong> I hate it when I miss something obvious, but @themel pointed me to it (thx again). Here's a full solution (note: works vectorized, so you can pass more than one color; only one alpha is supported at this time though):</p>
  
  <pre><code>#note: always pass alpha on the 0-255 scale
  makeTransparent&lt;-function(someColor, alpha=100)
  {
    newColor&lt;-col2rgb(someColor)
    apply(newColor, 2, function(curcoldata){rgb(red=curcoldata[1], green=curcoldata[2],
      blue=curcoldata[3],alpha=alpha, maxColorValue=255)})
  }
  </code></pre>