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? Thanks in advance, Patrick
On 5/27/07, Patrick Giraudoux <patrick.giraudoux at univ-fcomte.fr> 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?I can confirm that lattice does not produce "trellis" objects representing pie charts (although I guess it can be made to do so with a user supplied panel function). However, I don't see how that would have helped you with the map example, as plotting a "trellis" object would also include the axes, labels, etc. What you really want is the ability to draw a circle with differently colored angular segments, which can be reasonably approximated by polygons. polygon() and grid.polygon() do these for traditional and grid graphics respectively. -Deepayan
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. > > JimHey ! 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)))