title: R: Pie chart with percentage as labels using ggplot2
body: <p>From a data frame I want to plot a pie chart for five categories with their percentages as labels in the same graph in order from highest to lowest, going clockwise.</p>
  
  <p>My code is:</p>
  
  <pre><code>League&lt;-c("A","B","A","C","D","E","A","E","D","A","D")
  data&lt;-data.frame(League) # I have more variables 
  
  p&lt;-ggplot(data,aes(x="",fill=League))
  p&lt;-p+geom_bar(width=1)
  p&lt;-p+coord_polar(theta="y")
  p&lt;-p+geom_text(data,aes(y=cumsum(sort(table(data)))-0.5*sort(table(data)),label=paste(as.character(round(sort(table(data))/sum(table(data)),2)),rep("%",5),sep="")))
  p
  </code></pre>
  
  <p>I use</p>
  
  <pre><code>cumsum(sort(table(data)))-0.5*sort(table(data))
  </code></pre>
  
  <p>to place the label in the corresponding portion and</p>
  
  <pre><code>label=paste(as.character(round(sort(table(data))/sum(table(data)),2)),rep("%",5),sep="")
  </code></pre>
  
  <p>for the labels which is the percentages.</p>
  
  <p>I get the following output:</p>
  
  <pre><code>Error: ggplot2 doesn't know how to deal with data of class uneval
  </code></pre>