title: How to combine a plot and legend?
body: <p>I'm trying to attach a legend to a plot in R.
  I tried the following code ( taken from <a href="http://www.harding.edu/fmccown/r/" rel="nofollow">http://www.harding.edu/fmccown/r/</a> )</p>
  
  <pre><code># Define cars vector with 5 values
  cars &lt;- c(1, 3, 6, 4, 9)
  
  # Define some colors ideal for black &amp; white print
  colors &lt;- c("white","grey70","grey90","grey50","black")
  
  # Calculate the percentage for each day, rounded to one 
  # decimal place
  car_labels &lt;- round(cars/sum(cars) * 100, 1)
  
  # Concatenate a '%' char after each value
  car_labels &lt;- paste(car_labels, "%", sep="")
  
  # Create a pie chart with defined heading and custom colors
  # and labels
  pie(cars, main="Cars", col=colors, labels=car_labels,
     cex=0.8)
  
  # Create a legend at the right   
  legend(1.5, 0.5, c("Mon","Tue","Wed","Thu","Fri"), cex=0.8, 
     fill=colors)
  </code></pre>
  
  <p>However, this does not work really well. After the <strong>pie(cars, main="Cars", col=colors, labels=car_labels,cex=0.8)</strong> line , the plot is shown without a legend :-) .......Every example I see on the Internet seems to have the <strong>legend</strong> function after the plotting function so it seems very weird..............</p>
  
  <p>When I try to execute the legend function I get </p>
  
  <blockquote>
    <p>legend(1.5, 0.5, c("Mon","Tue","Wed","Thu","Fri"), cex=0.8, 
    +    fill=colors)
    Error in strwidth(legend, units = "user", cex = cex) : 
      plot.new has not been called yet</p>
  </blockquote>