File: placeLabels.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 (27 lines) | stat: -rwxr-xr-x 1,098 bytes parent folder | download | duplicates (5)
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
placeLabels<-function(x,y=NA,labels,pointer=TRUE,cex=1,labelcol=par("fg"),
 labelbg="white",border=par("fg"),pointercol=par("fg"),
 pch=1,col=1,bg="white",flagcol="red") {

 if(is.na(y) && is.list(x)) {
  y<-unlist(x[[2]])
  x<-unlist(x[[1]])
 }
 nlabels<-length(labels)
 if(length(labelcol) < nlabels) labelcol<-rep(labelcol,length.out=nlabels)
 if(length(labelbg) < nlabels) labelbg<-rep(labelbg,length.out=nlabels)
 if(length(border) < nlabels) border<-rep(border,length.out=nlabels)
 if(length(pointercol) < nlabels) pointercol<-rep(pointercol,length.out=nlabels)
 if(length(pch) < nlabels) pch<-rep(pch,length.out=nlabels)
 if(length(col) < nlabels) col<-rep(col,length.out=nlabels)
 if(length(bg) < nlabels) bg<-rep(bg,length.out=nlabels)
 for(i in 1:nlabels) {
  points(x[i],y[i],pch=19,col=flagcol)
  labelxy<-locator(1)
  if(pointer)
   segments(x[i],y[i],labelxy$x,labelxy$y,col=pointercol[i])
  boxed.labels(labelxy$x,labelxy$y,labels[i],
   col=labelcol[i],bg=labelbg[i],border=border[i])
  points(rep(x[i],2),rep(y[i],2),pch=c(19,pch[i]),
   col=c("white",col[i]),bg=c(NA,bg[i]))
 }
}