This function is used by draw.pie
to add a pie plot at a specific location to an existing plot. It can be used directly but in general it is advisable to use draw.pie
instead.
add.pie(z, x = 0, y = 0, labels = names(z), radius = 1, edges = 200, clockwise =
TRUE, init.angle = 90, density = NULL, angle = 45, col = NULL, border = NULL,
lty = NULL, label.dist = 1.1, ...)
a vector of non-negative numerical quantities. The values in z
are displayed as the areas of pie slices.
the location of the centre of the pie on the x and y-scale of the existing plot.
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.
the radius of the pie in units of the y-scale
the circular outline of the pie is approximated by a polygon with this many edges.
logical indicating if slices are drawn clockwise or counter clockwise (i.e., mathematically positive direction), the former is default.
number specifying the starting angle (in degrees) for the slices. see pie
for details.
the density of shading lines, in lines per inch. The default value of NULL means that no shading lines are drawn. Non-positive values of density also inhibit the drawing of shading lines.
the slope of shading lines, given as an angle in degrees (counter-clockwise).
a vector of colors 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.
(possibly vector) argument passed to polygon which draws each slice.
(possibly vector) argument passed to polygon which draws each slice.
distance that the label is placed away from the pie (relative to the radius)
graphical parameters
can be given as arguments to pie. They will affect the main title and labels only.
Adapted from the function pie
by Hans Gerritsen
Because this function is intended to add pie plots to a map, the radius is scaled to units on the y-scale. This is more convenient than using the x-scale as 1 degree latitude is exactly 60 nautical miles. (The conversion from degrees to distance on the x-scale is less straightforward as it depends on the latitude).
draw.pie
plot(NA,NA, xlim=c(-1,1), ylim=c(-1,1) )
add.pie(z=rpois(6,10), x=-0.5, y=0.5, radius=0.5)
add.pie(z=rpois(4,10), x=0.5, y=-0.5, radius=0.3)
Run the code above in your browser using DataLab