 <p>You need to call <code>rect</code> for each colour that you want to draw, and have those colours in a categorical column in your data frame so that you can filter the data per category for each call to <code>rect</code>.</p> <p>I don't know what your original data is like, so here's something similar:</p> <pre><code># set up simple plotting window plot.new() plot.window(xlim=c(0,6),ylim=c(0,8)) # example data. Using colour as the categorical value we will filter on sample.d &lt;- data.frame(x=c(3,4,5,6), yb=c(1,3,5,7), yt=c(0,2,4,6), colour=c("black","black","red","red")) # draw black rectangles black.d &lt;- sample.d[sample.d$colour == "black",] rect(0, black.d$yb, black.d$x, black.d$yt, col="black") # draw red rectangles red.d &lt;- sample.d[sample.d$colour == "red",] rect(0, red.d$yb, red.d$x, red.d$yt, col="red") </code></pre>