File: radial.plot.labels.R

package info (click to toggle)
r-cran-plotrix 3.8-4-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,588 kB
  • sloc: makefile: 6
file content (36 lines) | stat: -rwxr-xr-x 1,265 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
radial.plot.labels<-function(lengths,radial.pos=NULL,units="radians",
 radial.lim = NULL,start=0,clockwise=FALSE,labels,adj=NULL,pos=NULL,
 boxed.labels=FALSE,...) {
 
 npoints<-length(lengths)
 if(is.null(radial.pos))
  radial.pos<-seq(0,pi*(2-2/npoints),length.out=npoints)
 else {
  # clock24 starts at "midnight" and always runs clockwise
  if(units == "clock24") {
   if(is.character(radial.pos)) {
    splittime<-strsplit(radial.pos,":")
    hm2dh<-function(x) return(as.numeric(x[1])+as.numeric(x[2])/60)
    radial.pos<-sapply(splittime,hm2dh)
   }
   radial.pos<-pi*(450-radial.pos*15)/180
   start<-pi*(450-start*15)/180
  }
  # polar starts at 3 o'clock and runs counterclockwise by default
  if(units == "polar") {
   radial.pos <- pi * radial.pos/180
   start <- pi * start/180
  }
 }
 if(clockwise && units != "clock24") radial.pos<--radial.pos
 if (start && units != "clock24") radial.pos<-radial.pos+start
 if (is.null(radial.lim)) radial.lim <- range(lengths)
 lengths<-lengths-radial.lim[1]
 # get the vector of x positions
 xpos<-cos(radial.pos)*lengths
 # get the vector of y positions
 ypos<-sin(radial.pos)*lengths
 if(boxed.labels)
  boxed.labels(x=xpos,y=ypos,labels=labels,...)
 else text(x=xpos,y=ypos,labels=labels,adj=adj,pos=pos,...)
}