It might also be nice to be able to align the fans at the left or right, not just the center. On 9/23/06, Jim Lemon <jim at 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". > > 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 > } > } > > Jim > > ______________________________________________ > 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. >
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". 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 } } Jim
Gabor Grothendieck <ggrothendieck <at> gmail.com> writes:> > It might also be nice to be able to align the fans at the left or right, > not just the center.Fans that open only on one side: A line that moves like the minute needle of an analog clock; with zero at the top. Movement of the needle in clock-wise direction represents the number (precentage). Anupam.
Anupam Tyagi
2006-Sep-26 16:21 UTC
[R] Extention of Pie Chart in R (was Re: Adding percentage to Pie Charts)
Jim Lemon <jim <at> bitwrit.com.au> writes:> I admit to interpreting this pretty loosely, but I would like to know > what people think of a "fan plot".Hi all, I tried the fan.plots that Jim has been very nice to provide. It made me think if there was something like, "clock.plots" in R? Something like the following, anything that comes close? The idea an extention in yet another way of Pie Charts, extending the fan.plots provided by Jim. * A value will be depicted on a "clock.plot" using 1 or 2 hands of an analog clock on a circle calibrated from 0 to 100 (same as 0). * For values between 0 and 99 use the position of only one hand of the clock (needle). * For values of 100, use the second hand (needle), and move it to 1. * Some way to identify needles, and two two overlapping needles. * Use color coding or line-types to differentiate variables. This is basically a clock calibrated on a scale of 100, rather than 60. It can visually depict values between 1 and 10000. Do we have something like this R? Anupam.