title: Adding a continuous color gradient legend strip to plot
body: <p>I am using following data and code to plot a <code>barplot</code>: </p>
  
  <pre><code>ddf=structure(list(VAR = structure(1:9, .Label = c("aaa", "bbb", 
  "ccc", "ddd", "eee", "fff", "ggg", "hhh", "iii"), class = "factor"), 
      VAL = c(0L, 32L, 64L, 96L, 128L, 160L, 192L, 224L, 256L)), .Names = c("VAR", 
  "VAL"), class = "data.frame", row.names = c(NA, -9L))
  
  barplot(ddf$VAL,col=rgb(ddf$VAL,256-ddf$VAL,0,maxColorValue=256))
  </code></pre>
  
  <p>How can I add a legend strip having these colors on it, with corresponding values written there? I want a legend strip as appears in following plot: </p>
  
  <pre><code>library(latticeExtra)
  dat &lt;- data.frame(x = rnorm(1000), y = rnorm(1000), z = rnorm(1000, mean = 1))
  maxz &lt;- max(abs(dat$z))
  levelplot(z ~ x * y, dat, at = seq(-maxz, maxz, length = 100), panel = panel.levelplot.points, par.settings = custom.theme.2())
  </code></pre>
  
  <p>I have tried to use following function examples but am unable to modify them to my needs: </p>
  
  <pre><code>legend("bottom", legend = LETTERS[1:6], col = c6, ncol = 2, cex = 2, lwd = 3, text.font = i, text.col = c6)
  
  libarary(plotrix)
  testcol&lt;-color.gradient(c(0,1),0,c(1,0),nslices=5)
  color.legend(11,6,11.8,9,col.labels,testcol,gradient="y")
  </code></pre>
  
  <p>Thanks in advance.</p>