How to create a pie chart in R


  R Interview Questions

Pie charts do not represent a lot of value from a statistician’s perspective, but they are a simple way to show proportions in an easy manner to the layman.

> summary = table(mtcars$cyl)
> summary
 4  6  8 
11  7 14 
> pie(summary)

Unfortunately, standard pie() function does not allow percentages to show up on the pie chart. We would have to calculate it ourselves manually.

> labels = summary * 100 / sum(summary)
> labels
     4      6      8 
34.375 21.875 43.750 
> labels = round(labels)
> labels
 4  6  8 
34 22 44 
> pie(summary,labels)

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.