Grid-Based Pie Charts

Share:

Description

Draw a grid-based pie chart.

Usage

1
2
3
gpie(x, labels = names(x), edges = 200, radius = 0.8,
     clockwise = FALSE, init.angle = if (clockwise) 90 else 0,
     col = NULL, border = NULL, lty = NULL)

Arguments

x

a vector of non-negative numerical quantities. The values in x are displayed as the areas of pie slices.

labels

one or more expressions or character strings giving names for the slices. Other objects are coerced by as.graphicsAnnot. For empty or NA (after coercion to character) labels, no label nor pointing line is drawn.

edges

the circular outline of the pie is approximated by a polygon with this many edges.

radius

the pie is drawn centred in a square box whose sides range from -1 to 1. If the character strings labelling the slices are long it may be necessary to use a smaller radius.

clockwise

logical indicating if slices are drawn clockwise or counter-clockwise (i.e., mathematically positive direction), the latter is default.

init.angle

number specifying the starting angle (in degrees) for the slices. Defaults to 0 (i.e., '3 o'clock') unless clockwise is true where 'init.angle' defaults to 90 (degrees), (i.e., 12 o'clock').

col

a vector of colours to be used in filling or shading the slices. If missing a set of 6 pastel colours is used, unless density is specified when par("fg") is used.

border

a vector of colours to be used in drawing the borders of the slices.

lty

argument linetype passed to grid.polygon

Author(s)

Original code by Thomas S. Dye. Modified by Ingo Voglhuber.

See Also

gbarplot, gmatplot, gstars, gsymbols, gbxp

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
grid.newpage()

gpie(rep(1, 24), col = rainbow(24), radius = 0.9)

grid.newpage()

pie.sales <- c(0.12, 0.3, 0.26, 0.16, 0.04, 0.12)
names(pie.sales) <- c("Blueberry", "Cherry",
    "Apple", "Boston Cream", "Other", "Vanilla Cream")
gpie(pie.sales) # default colours

grid.newpage()

gpie(pie.sales,
    col = c("purple", "violetred1", "green3", 
            "cornsilk", "cyan", "white"))

grid.newpage()

gpie(pie.sales, col = gray(seq(0.4,1.0,length=6)))

grid.newpage()

gpie(pie.sales, clockwise=TRUE)