# # custom function to draw radar chart (a.k.a. spider chart or star chart) # rev. 1.0 on 2 February 2008. # rev. 1.1 on 13 February 2008, vectorized et al. due to Dr. Aoki's comments. # rev. 1.2 on 24 March 2008, bug fix for error treatment / printing axis label (option). # rev. 1.3 on 8 April 2009, plotting dot / interpolation for many missing data # rev. 2.0 on 22 April 2009, the form of data-frame changed. # code developed by Minato Nakazawa # freely distributable and being used for any purpose # Primary site to distribute is, http://phi.med.gunma-u.ac.jp/swtips/radarchart2.R # radarchart <- function(df,axistype=0,seg=4,pty=16,pcol="black",ldtype=0,title="") { if (!is.data.frame(df)) return() if ((n <- length(df))<3) return() plot(c(-1.2,1.2),c(-1.2,1.2),type="n",frame.plot=F,axes=F,xlab="",ylab="",main=title,asp=1) theta <- seq(90,450,length=n+1)*pi/180 theta <- theta[1:n] xx <- cos(theta) yy <- sin(theta) for (i in 0:seg) { polygon(xx*(i+1)/(seg+1),yy*(i+1)/(seg+1),lty=3,lwd=1,border="navy") if (axistype==1|axistype==3) text(-0.05,(i+1)/(seg+1),paste(i/seg*100,"(%)"),col="blue") } arrows(xx/(seg+1),yy/(seg+1),xx*1,yy*1,lwd=1,lty=3,length=0,col="navy") if (axistype==2) { text(xx[1:n],yy[1:n],df[1,1:n],col="blue") } text(xx*1.2,yy*1.2,colnames(df)) series <- length(df[[1]]) for (i in 3:series) { xxs <- xx yys <- yy for (j in 1:n) { if (is.na(df[i,j])) { left <- ifelse(j>1,j-1,n-1) while (is.na(df[i,left])) { left <- ifelse(left>0,left-1,n-1) } right <- ifelse(j