[R] A polar.plot BUG in plotrix 1.3.3 ?

Halldor Björnsson halldor at vedur.is
Wed Jun 22 14:38:14 CEST 2005


Hi,

I just updated to R-2.1.1 and updated packages acordingly

However, after the update, routines that use polar.plot
did not function as correctly.

In plotrix 1.3.3 the polar.plot function does scale label.pos
to radians prior to calling radial.plot

Hence, the command
polar.plot(c(5,10,5,0),c(-10,0,10,20),rp.type='P',
     labels=c("A","N","V","S"),label.pos=c(0,90,180,270))

produces absurd compass lines but the correct results are obtained if 
label.pos is scaled with pi/180 :

polar.plot(c(5,10,5,0),c(-10,0,10,20),rp.type='P',
     labels=c("A","N","V","S"),label.pos=c(0,90,180,270)*pi/180)

I have attatched the polar.plot function from the two different versions 
of the package.

It seems that if not missing  then label.pos is not changed at all in 
version 1.3.3

So, a feature or a bug?

Sincerely,
-- 
------------------------------------------
Halldor Bjornsson   (halldor at vedur.is)
Vedurstofa Islands (Icelandic Met. Office)
Bustadavegur 9, IS-150, Reykjavik, Iceland
------------------------------------------

In version 1.3.3

polar.plot<-function(lengths,polar.pos,labels,label.pos,rp.type="r",...) {
  npos<-length(lengths)
  # if no positions are given, add the average distance between 
positions so that
  # the first and last line don't overlap
  if(missing(polar.pos)) radial.pos<-seq(0,(2-2/(npos+1))*pi,length=npos)
  else radial.pos<-pi*polar.pos/180
  if(missing(labels)) {
   labels<-as.character(seq(0,340,by=20))
   label.pos<-seq(0,1.9*pi,length=18)
  }
  if(missing(label.pos)) label.pos<-pi*label.pos/180
  radial.plot(lengths,radial.pos,range(radial.pos),labels,label.pos,
   rp.type=rp.type,...)
}



In version 1.2

polar.plot<-function(lengths,polar.pos,labels,label.pos,rp.type="r",...) {
  npos<-length(lengths)
  # if no positions are given, add the average distance between 
positions so that
  # the first and last line don't overlap
  if(missing(polar.pos)) polar.pos<-seq(0,360-360/(npos+1),length=npos)
  if(missing(labels)) {
   label.pos<-seq(0,340,by=20)
   labels<-as.character(label.pos)
   label.range<-c(0,pi*340/180)
  }
  if(missing(label.pos)) label.pos<-polar.pos
  polar.range<-range(polar.pos)
  newrange<-c(pi*polar.range[1]/180,pi*(2-(360-polar.range[2])/180))
  # rescale to radians
  radial.pos<-rescale(c(polar.pos,polar.range),newrange)[1:npos]
  nlabels<-length(labels)
  label.pos<-rescale(c(label.pos,0,360),c(0,2*pi))[1:nlabels]

radial.plot(lengths,radial.pos,newrange,labels,label.pos,rp.type=rp.type,...)
}




More information about the R-help mailing list