[R-sig-Geo] How to diplasy a compass rose on a map

Jim Lemon jim at bitwrit.com.au
Thu Feb 4 01:48:07 CET 2010


On 02/04/2010 05:56 AM, Everton Emanuel wrote:
> Dear all,
>
> I want to display a "compass rose" on a map, but I have no idea how
> to do that. Do you know how can I display a compass rose on a map?
>
Hi Everton,
Here's a very basic compass rose function. rot is in degrees. I'll tart
it up a bit and put it in the next version of plotrix, unless the Geo
people think it should go in one of the mapping packages.

Jim

compassRose<-function(x,y,rot=0,cex=1) {
  oldcex<-par(cex=cex)
  mheight<-strheight("M")
  xylim<-par("usr")
  plotdim<-par("pin")
  xmult<-(xylim[2]-xylim[1])/(xylim[4]-xylim[3])*plotdim[2]/plotdim[1]
  point.angles<-seq(0,7*pi/4,by=pi/4)+pi*rot/180
  crspans<-rep(c(mheight*3,mheight/2),4)
  xpoints<-cos(point.angles)*crspans*xmult+x
  ypoints<-sin(point.angles)*crspans+y
  polygon(xpoints,ypoints)
  txtxpoints<-cos(point.angles[c(1,3,5,7)])*1.33*crspans[1]*xmult+x
  txtypoints<-sin(point.angles[c(1,3,5,7)])*1.33*crspans[1]+y
  text(txtxpoints,txtypoints,c("E","N","W","S"))
  par(oldcex)
}



More information about the R-sig-Geo mailing list