Hi All,

I'm trying to find out a way to plot multi-panel pie charts. It may not be
the best way to present data, but I would still need one.

1. Is anyone aware of some in-built script/function which can do this for
me. I'm aware of one given in Deepayan's book, but anything apart from this?


2. I tried using Deepayan's script on following data set but it doesn't seem
to work as expected - labels are getting repeated/overlapping. I'm really
not sure what could be the problem, can anyone help please. I hope data is
in the right format, as expected.

 Data read into object "foo":

variable month value
ProdA   Jan    25
ProdA   Feb    30
ProdA   Mar    25
ProdA   Apr    10
ProdB   Jan    25
ProdB   Feb    30
ProdB   Mar    50
ProdB   Apr    40
ProdC   Jan    40
ProdC   Feb    30
ProdC   Mar    20
ProdC   Apr    40
ProdD   Jan    10
ProdD   Feb    10
ProdD   Mar     5
ProdD   Apr    10

R Code: as it is from the book,

library(lattice)
library(grid)
library(gridBase)

panel.piechart <-
    function(x, y, labels = as.character(y),
             edges = 200, radius = 0.8, clockwise = FALSE,
             init.angle = if(clockwise) 90 else 0,
             density = NULL, angle = 45,
             col = superpose.polygon$col,
             border = superpose.polygon$border,
             lty = superpose.polygon$lty, ...)
{
    stopifnot(require("gridBase"))
    superpose.polygon <- trellis.par.get("superpose.polygon")
    opar <- par(no.readonly = TRUE)
    on.exit(par(opar))
    if (panel.number() > 1) par(new = TRUE)
    par(fig = gridFIG(), omi = c(0, 0, 0, 0), mai = c(0, 0, 0, 0))
    pie(as.numeric(x), labels = labels, edges = edges, radius = radius,
        clockwise = clockwise, init.angle = init.angle, angle = angle,
        density = density, col = col, border  = border, lty = lty)
}

piechart <- function(x, data = NULL, panel = "panel.piechart", ...)
{
    ocall <- sys.call(sys.parent())
    ocall[[1]] <- quote(piechart)
    ccall <- match.call()
    ccall$data <- data
    ccall$panel <- panel
    ccall$default.scales <- list(draw = FALSE)
    ccall[[1]] <- quote(lattice::barchart)
    ans <- eval.parent(ccall)
    ans$call <- ocall
    ans
}

## Figure 14.5
par(new = TRUE)
piechart(foo)

Thanks in advance,
Gurmeet

        [[alternative HTML version deleted]]

______________________________________________
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

Reply via email to