Chapter 10. Pie Charts

Ordinary Pie Chart

The pie chart is one of the most familiar types of graph. It would be difficult to imagine that you have not seen hundreds of them. One place where they seem to be taken for granted is in the realm of investment portfolios. Investment advisors recommend that their clients allocate their holdings to certain categories of investment, in specified amounts. Such recommendations are usually presented in the form of pie charts. Fund managers also report their holdings (at a point in time) in a similar way. Consider the following portfolio, allocated to “sectors” (this is not a recommendation, by the way):

  • Domestic stocks—30 percent

  • Foreign stocks—25 percent

  • Bonds—28 percent

  • Gold/precious metals—10 percent

  • Cash equivalents—7 percent

We can make a vector out of the percentages and use the pie() function to produce the desired chart, as shown in the following script:

 # Script for Figure 10-1 par(mfrow = c(2,2)) allocation = c(30,25,28,10,7) # investment allocations # sector & sectcol will be reused; we won't have to retype them sector = c("Stock","For'n'","Bonds", "Gold","Cash") # names fit page sectcol = c("burlywood","turquoise","firebrick", "gold3","green4") # Figure 10-1 top left pie(allocation, labels = sector, main = "pie, default colors") # Figure 10-1 top right pie(allocation, labels = sector, col = sectcol, main = "pie, choose colors") # Figure 10-1 bottom left install.packages("plotrix", dependencies = TRUE) library(plotrix) ...

Get Graphing Data with R now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.