Togaware DATA MINING
Desktop Survival Guide
by Graham Williams
Google

Fan Plot



fan.plot<-function(x,edges=200,radius=1,col=NULL,centerpos=pi/2,
  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)
  oldpar<-par(no.readonly=TRUE)
  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)
   xc<-c(cos(t2p)*radius,0)
   yc<-c(sin(t2p)*radius,0)
   polygon(xc,yc,col=col[xorder[i]],...)
   if(!is.null(labels)) {
    xpos<-lside*sin(x[xorder[i]])*radius
    ypos<--i/10
    text(xpos,ypos,labels[xorder[i]])
    ytop<-cos(x[xorder[i]])*radius*radius
    segments(xpos,ypos+1/20,xpos,ytop)
    lside<--lside
   }
   radius<-radius-0.02
  }
}

fan.plot(c(20,38,3,17))



Copyright © Togaware Pty Ltd
Support further development through the purchase of the PDF version of the book.
The PDF version is a formatted comprehensive draft book (with over 800 pages).
Brought to you by Togaware. This page generated: Sunday, 22 August 2010