Pie Charts

DESCRIPTION:

Creates a pie chart from a vector of data. Several options are available to customize the plot.

USAGE:

pie(x, names = NULL, explode = F, style.pie = list(), size = .75,  
    inner = .3, outer = 1.1, angle = <<see below>>,  
    density = <<see below>>, col = 1:12, rotate = T, ...) 

REQUIRED ARGUMENTS:

x
vector of relative pie slice sizes. The ith slice will take the fraction abs(x[i])/sum(abs(x)) of the pie. The slices start with a horizontal line to the right and go counter-clockwise. Missing values are not accepted.

OPTIONAL ARGUMENTS:

names
vector of character strings containing the slice labels. Labels are positioned along the center-line of the slice, and are shifted as far in toward the center as possible without overlapping into adjacent slices (see arguments inner, outer, and rotate).
explode
logical vector specifying slices of the pie which should be exploded (moved out from the center). If this is shorter than x, it is reused cyclically.
style.pie
character string or list indicating the style of the pie chart. If specified as a character string, the string is appended to " pie." to get the name of a dataset which is a list. Component names of this list should match the names of the parameters below; the component values serve as the defaults for the corresponding parameters (i.e., other arguments supplied to the function override the style.pie component values). Standard style.pie option values include "splus" and "old".
size
fraction of the short dimension of the plot taken up by the circle.
inner
fraction giving the innermost position that labels can occupy. The default value of .3 means that labels can go no further toward the center than .3 of the radius.
outer
fraction giving the outer limit for starting the labels.
angle
vector giving the angle (degrees, counter-clockwise from horizontal) for shading each slice. (The default is 45 if density is supplied.)
density
vector for pie shading, giving the number of lines per inch for shading each slice. The default is 5 if angle is supplied. A density of 0 implies solid filling, and is the default if col has more than one color and angle is not supplied. Negative values of density produce no shading which is the default if col has only one color and angle is not supplied.
col
vector giving the colors in which the pie slices should be filled or shaded. If col is supplied and neither angle nor density are given as arguments, slices will be filled solidly or unfilled. In this case, if there is only one color specified, the slices will be unfilled. Otherwise, they will be filled solidly. Note, the special value, NA, can be used to indicate that the current par("col") value is to be used for the fill or shading color.
rotate
logical flag controlling rotation of slice labels. If TRUE, names are drawn parallel to the center line of each slice. If FALSE, names are drawn horizontally. This is convenient if the graphics device has a limited capability for character rotation.

Graphical parameters may also be supplied as arguments to this function (see par ). In addition, the high-level graphics arguments described under plot.default and the arguments to title may be supplied to this function.

SIDE EFFECTS:

a pie chart (a circle divided into wedges) is produced on the current graphics device.

DETAILS:

Solid filling of pie slices is dependent on the area-filling capability of the device driver. For devices without explicit area-filling capability, solid filling can be simulated by specifying a very high density shading. The default options are geared towards devices that have color or halftoning capabilities, such as motif and postscript.

Specifying style="old" will set the defaults to produce a pie chart with unfilled slices drawn with the current par("col") value.

BACKGROUND:

Pie charts are most useful when the emphasis is on individual item's relation to the total. When such an emphasis is not the primary point of the graphic, a bar chart or a dot chart is preferred.

REFERENCES:

Cleveland, W. S. (1985). The Elements of Graphing Data. Wadsworth, Monterey, California.

SEE ALSO:

attributes , barplot , dotchart , par , plot , title .

EXAMPLES:

# create a plot from one student's testscores 
datest <- (testscores[18,]) 
name <- attributes(datest) 
pie(datest, names = name, col = c(3:7)) 
# explode testscores < 20 percent 
pie(datest, names = name, col = c(3:7), explode = datest < 20) 
# force the labels to be outside the chart 
pie(datest, names = name, col = c(3:7), explode = datest < 20, 
    inner = .95) 
# pie chart created with a user defined style 
pie.mystyle <- list(col=1:100, inner=1.1, rotate=F) 
pie(revenues, names=revenue.class, style.pie="mystyle") 
datatel <- apply(telsam.response, 2, sum) 
pie(datatel, dimnames(telsam.response)[[2]], explode = c(T, F, F, F), 
    col = c(3:6)) 
title(main = 
"Response to Quality of Service Questions\nConcerning Telephone Service")