View source: R/panel_piechart.R
panel.piechart | R Documentation |
This panel function allows to draw pie charts (or rings) while still being able to use the typical lattice way of subsetting data. The function can be used within 'xyplot()' but only one variable needs to be supplied ('x'). Grouping is supported in the sense that the 'x' variable is aggregated (summed up) over each unique group.
panel.piechart(
x,
groups = NULL,
subscripts = NULL,
fun = function(x) sum(x, na.rm = TRUE),
diameter_inner = 0.1,
diameter_sector = 0.2,
clockwise = FALSE,
start_angle = if (clockwise) 90 else 0,
draw_labels = TRUE,
col = NULL,
border = NULL,
lty = NULL,
lwd = NULL,
cex = NULL,
...
)
x |
(numeric, character) variable to be plotted |
groups |
grouping variable passed down from 'xyplot' (does not need to be specified) |
subscripts |
subscripts passed down from 'xyplot' (does not need to be specified) |
fun |
(function) used to perform optional aggregation over groups (default: sum) |
diameter_inner |
(numeric) diameter of the inner circle of the pie/ring (default: 0.1) |
diameter_sector |
(numeric) diameter of the outer circle of the pie/ring (default: 0.2) |
clockwise |
not implemented yet |
start_angle |
not implemented yet |
draw_labels |
(logical) switch drawing of labels on or off (default: TRUE) |
col, border, lty, lwd, cex |
(character, numeric) graphical parameters |
... |
other arguments passed to the function |
library(grid)
library(lattice)
data("USMortality")
# A simple example using lattice paneling
xyplot( ~ Rate | Sex, USMortality,
main = "US mortality rates by sex",
scales = list(draw = FALSE), cex = 0.7,
panel = function(x, ...) {
panel.piechart(x, ...)
}
)
# A more advanced example using grouping and
# adjusting graphical parameters. The main variable
# 'x' is now summed up for each value of 'groups'
xyplot( ~ Rate | Sex, USMortality,
groups = gsub(" ", "\n", Cause),
col = heat.colors(10),
border = grey(0.3), cex = 0.7,
main = "US mortality rates by sex",
scales = list(draw = FALSE),
panel = function(x, ...) {
panel.piechart(x, diameter_sector = 0.1, ...)
}
)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.