Free Trial

Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.

  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint
Share this Page URL
Help

13. Miscellaneous Graphs > Creating a Pie Chart

Creating a Pie Chart

Problem

You want to make a pie chart.

Solution

Use the pie() function. In this example (Figure 13-31), we’ll use the survey data set from the MASS library:

library(MASS)  # For the data set

# Get a table of how many cases are in each level of fold
fold <- table(survey$Fold)
fold

 L on R Neither  R on L
     99      18     120

# Make the pie chart
pie(fold)
A pie chart
Figure 13-31. A pie chart

We passed pie() an object of class table. We could have instead given it a named vector, or a vector of values and a vector of labels, like this:

pie(c(99, 18, 120), labels=c("L on R", "Neither", "R on L"))

Discussion

The lowly pie chart is the subject of frequent abuse from data visualization experts. If you’re thinking of using a pie chart, consider whether a bar graph (or stacked bar graph) would convey the information more effectively. Despite their faults, pie charts do have one important virtue: everyone knows how to read them.


  

You are currently reading a PREVIEW of this book.

                                                                                                                    

Get instant access to over $1 million worth of books and videos.

  

Start a Free 10-Day Trial


  
  • Safari Books Online
  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint