title: R ggplot2 - convert row records to vertical values and use in geom_polygon
body: <p>I have some items that have different eligibility criteria - specifically in this example two variables each with a min and max the values are allowed to take.  I would like to see the coverage of the products by plotting rectangles for each product on a chart that shows the area between the mins and maxs.</p>
  <p><strong>How would you go about</strong></p>
  <ul>
  <li>converting the records most elegantly to that required by geom_polygon() and</li>
  <li>ensuring the shapes produced appear as rectangles</li>
  </ul>
  <p><strong>Example</strong></p>
  <pre><code>library(data.table)
  library(ggplot2)
  df&lt;-data.table(Product=letters[1:10], minX=1:10, maxX=5:14, minY= 10:1, maxY=14:5)
  
  df.t&lt;-data.table(rbind( df[,list(Product,X=minX,Y=minY)],
         df[,list(Product,X=minX,Y=maxY)],
         df[,list(Product,X=maxX,Y=minY)],
         df[,list(Product,X=maxX,Y=maxY)]))[
        order(Product,X,Y)]
  
  ggplot(df.t,aes(x=X,y=Y,group=Product,fill=Product))+geom_polygon()
  </code></pre>
  <p><img src="https://i.stack.imgur.com/Hpw2D.png" alt="Result" /></p>
  <p>NB In this reduced example there are only two criteria, however I have a range of criteria columns and would not want to repeat the exercise above for different combinations.</p>