File: boxed.labels.R

package info (click to toggle)
r-cran-plotrix 3.2-6-1
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 1,136 kB
  • sloc: makefile: 3
file content (34 lines) | stat: -rwxr-xr-x 1,133 bytes parent folder | download
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
boxed.labels<-function(x,y=NA,labels,
 bg=ifelse(match(par("bg"),"transparent",0),"white",par("bg")),
 border=TRUE,xpad=1.2,ypad=1.2,srt=0,cex=1,adj=0.5,...) {

 oldcex<-par("cex")
 par(cex=cex)
 if(is.na(y) && is.list(x)) {
  y<-unlist(x[[2]])
  x<-unlist(x[[1]])
 }
 box.adj<-adj+(xpad-1)*cex*(0.5-adj)
 # boxes can only be rotated 90 degrees either way
 if(srt==90 || srt==270) {
  bheights<-strwidth(labels)
  theights<-bheights*(1-box.adj)
  bheights<-bheights*box.adj
  lwidths<-rwidths<-strheight(labels)*0.5
 }
 else {
  lwidths<-strwidth(labels)
  rwidths<-lwidths*(1-box.adj)
  lwidths<-lwidths*box.adj
  bheights<-theights<-strheight(labels)*0.5
 }
 # fix for adding a col argument to ... by Thorn Thaler
 args <- list(x = x, y = y, labels = labels, srt = srt, adj = adj, 
             col = ifelse(colSums(col2rgb(bg) * c(1, 1.4, 0.6)) < 
                          350, "white", "black"))
 args <- modifyList(args, list(...))
 rect(x - lwidths * xpad, y - bheights * ypad, x + rwidths * 
     xpad, y + theights * ypad, col = bg, border = border)
 do.call(text, args)
 par(cex=oldcex)
}