[R] Pie chart

Jim Lemon jim at bitwrit.com.au
Sat May 25 01:10:18 CEST 2013


On 05/25/2013 06:08 AM, Jose Narillos de Santos wrote:
> I have a 8 Groups composed by A,B, c, D components. The Group 9 is composed
> by the 8 Groups but only components A and C.
>
>
> I want to chart a plot with 1 big plot of the total Groups (from 1 to 8) on
> the right and 8 mini pies on the left composed by the 4 components (the
> size of each pie of group should be bigger or smaller depending on the
> total).
>
> The same structure but below this plot I want to put on the left the plot
> of Group 9 composed by Component A and C and on the left 8 pies composed by
> Component B and C on Each Group.
>
> I don´t know if it is posible.....
>
Hi Jose,
Not only possible...

Group1<-c(1100,1000,100)
Group2<-c(728,380,38,10,300)
Group3<-c(320,200,20,50,50)
Group4<-c(110,80,8,20,2)
Group5<-c(75,40,4,5,26)
Group6<-c(38,30,3,2,3)
Group7<-c(16,10,1,5)
Group8<-c(10.5,5,0.5,4,1)
Total<-c(2397.5,1745,174.5,91,387)
Group9<-c(1836,1745,0,91,0)
x11(width=10,height=5)
par(mar=c(1,1,1,1))
plot(0,xlim=c(0,4),ylim=c(0,5),type="n",axes=FALSE)
piecol<-2:6
require(plotrix)
totalpos<-floating.pie(1,2.5,Total,col=piecol)
pielab<-LETTERS[1:5]
pie.labels(1,2.5,totalpos,pielab)
g1pos<-floating.pie(2.3,4,Group1,radius=0.2,col=piecol)
pie.labels(2.3,4,g1pos,pielab[1:3],radius=0.2)
g2pos<-floating.pie(2.7,3,Group2,radius=0.2,col=piecol)
pie.labels(2.7,3,g2pos,pielab,radius=0.2)
g3pos<-floating.pie(2.3,2,Group3,radius=0.2,col=piecol)
pie.labels(2.3,2,g3pos,pielab,radius=0.2)
g4pos<-floating.pie(2.7,1,Group4,radius=0.2,col=piecol)
pie.labels(2.7,1,g4pos,pielab,radius=0.2)
g5pos<-floating.pie(3.3,4,Group5,radius=0.2,col=piecol)
pie.labels(3.3,4,g5pos,pielab,radius=0.2)
g6pos<-floating.pie(3.7,3,Group6,radius=0.2,col=piecol)
pie.labels(3.7,3,g6pos,pielab,radius=0.2)
g7pos<-floating.pie(3.3,2,Group7,radius=0.2,col=piecol[c(1:3,5)])
pie.labels(3.3,2,g7pos,pielab[c(1:3,5)],radius=0.2)
g8pos<-floating.pie(3.7,1,Group8,radius=0.2,col=piecol)
pie.labels(3.7,1,g8pos,pielab,radius=0.2)

That should get you started. I think I will modify floating.pie so that 
it just ignores zero or NA values in the sector proportions.

Jim



More information about the R-help mailing list