| 1 |
compassRose<-function(x,y,rot=0,cex=1) { |
| 2 |
oldcex<-par(cex=cex) |
| 3 |
mheight<-strheight("M") |
| 4 |
xylim<-par("usr") |
| 5 |
plotdim<-par("pin") |
| 6 |
xmult<-(xylim[2]-xylim[1])/(xylim[4]-xylim[3])*plotdim[2]/plotdim[1] |
| 7 |
point.angles<-seq(0,2*pi,by=pi/4)+pi*rot/180 |
| 8 |
crspans<-rep(c(mheight*3,mheight/2),length.out=9) |
| 9 |
xpoints<-cos(point.angles)*crspans*xmult+x |
| 10 |
ypoints<-sin(point.angles)*crspans+y |
| 11 |
for(point in 1:8) { |
| 12 |
pcol<-ifelse(point%%2,"black","white") |
| 13 |
polygon(c(xpoints[c(point,point+1)],x),c(ypoints[c(point,point+1)],y),col=pcol) |
| 14 |
} |
| 15 |
txtxpoints<-cos(point.angles[c(1,3,5,7)])*1.2*crspans[1]*xmult+x |
| 16 |
txtypoints<-sin(point.angles[c(1,3,5,7)])*1.2*crspans[1]+y |
| 17 |
text(txtxpoints,txtypoints,c("E","N","W","S")) |
| 18 |
par(oldcex) |
| 19 |
} |