Skip to Main Content
Graphing Data with R
book

Graphing Data with R

by John Jay Hilfiger
October 2015
Beginner to intermediate content levelBeginner to intermediate
250 pages
6h 26m
English
O'Reilly Media, Inc.
Content preview from Graphing Data with R

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) ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

A Course in Statistics with R

A Course in Statistics with R

Prabhanjan N. Tattar, Suresh Ramaiah, B. G. Manjunath

Publisher Resources

ISBN: 9781491922606Errata Page