# Re: [R] Adding percentage to Pie Charts

From: Gabor Grothendieck <ggrothendieck_at_gmail.com>
Date: Sun 24 Sep 2006 - 01:42:28 GMT

On 9/23/06, Jim Lemon <jim@bitwrit.com.au> wrote:
> Hi all,
>
> Anupam Tyagi mentioned an interesting idea a few days ago.
>
> "A modification in a pie chart that draws overlapping areas with a
> common start point at the top of the circle, can make is more
> informative than a dot-chart.
> Something like:
> * Start drawing at the top of the circle, as zero (degree/area).
> * Draw the representation of every value starting from the top, as zero,
> representing it as a labled line from the center of the circle to the
> boundary
> (can use colors where possible).
> * Use two lables for the circular axis, inside one for percentages,
> outside for values."
>
> I admit to interpreting this pretty loosely, but I would like to know
> what people think of a "fan plot".
>
> labels=NULL,...) {
>
> if (!is.numeric(x) || any(is.na(x) | x<=0))
> stop("fan.plot: x values must be positive.")
> # scale the values to a half circle
> x<-pi*x/sum(x)
> xorder<-order(x,decreasing=TRUE)
> nx <- length(x)
> if (is.null(col)) col<-rainbow(nx)
> else if(length(col) < nx) col<-rep(col,nx)
> par(mar=c(0,0,4,0))
> plot(0,xlim=c(-1,1),ylim=c(-0.6,1),xlab="",ylab="",type="n",axes=FALSE)
> lside<--0.8
> for(i in 1:nx) {
> n<-edges*x[xorder[i]]/pi
> t2p<-seq(centerpos-x[xorder[i]],centerpos+x[xorder[i]],length=n)
> polygon(xc,yc,col=col[xorder[i]],...)
> if(!is.null(labels)) {
> ypos<--i/10
> text(xpos,ypos,labels[xorder[i]])
> segments(xpos,ypos+1/20,xpos,ytop)
> lside<--lside
> }
> }
> }
>
> Jim
>
> ______________________________________________
> R-help@stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help