Re: [R] pie chart in lattice - trellis class

From: Patrick Giraudoux <patrick.giraudoux_at_univ-fcomte.fr>
Date: Mon, 28 May 2007 15:05:07 +0200

Jim Lemon a écrit :
> Patrick Giraudoux wrote:
>> Dear all,
>>
>> After going through the Lattice doc and R-help list and google, I got
>> the feeling that there is no function in lattice or other package to
>> compute a pie chart object of class "trellis". Although pie charts
>> are obviously not considered optimal even in the pie() doc ;-) , pie
>> chart trellis objects would be easy positioned e.g. over a map drawn
>> with the grids package.
>>
>> Can anybody confirm this absence or indicate a package/function able
>> to draw a pie chart object of class trellis?
>>
> Hi Patrick,
> Floating.pie was written to solve this problem, but it only works in
> standard graphics. Perhaps it might help, though.
>
> Jim

Hey ! Looks like exactly the one I was looking for... For info to other R-users, it can be found in the 'plotrix' package. Meanwhile I had dropped some line codes with the same target, still not fully achieved (the argument center is not taken into account yet... needs one line more).

Thanks a lot!

Patrick

polycirc2<-function (radius=1, center = c(0, 0), edges = 50, init=pi/2, angle=pi/2)
{

    circ = NULL
    angles <- seq(init, init+angle, l = edges)     for (i in angles) {

        circ <- rbind(circ, cbind(radius * sin(i), radius * cos(i)))     }
    circ<-rbind(c(0,0),circ)
    return(cbind(circ[, 1] + center[1], circ[,2] + center[2])) }

pie2<-function(x,col=NULL,...){

    x<-x/sum(x)
    xC<-cumsum(x)
    xC<-xC/xC[length(xC)]
    init=0

        for (i in 1:length(x)) {
        angle<-x[i]*2*pi
        polygon(polycirc2(init=init,angle=angle),col=col[i],...)
        init<-xC[i]*2*pi

    }
}

# example
ex<-rpois(10,2)
plot(c(-1,+1),c(-1,+1),type="n",asp=1)
pie2(ex,col=c(1:length(ex)))



R-help_at_stat.math.ethz.ch 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. Received on Mon 28 May 2007 - 13:10:47 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Mon 28 May 2007 - 14:31:42 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.