File: textbox.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 (24 lines) | stat: -rwxr-xr-x 698 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
textbox<-function(x,y,textlist,justify=TRUE,cex=1,leading=0.5,box=TRUE) {
 par(adj = 0)
 textstr <- paste(textlist, collapse = " ")
 words <- strsplit(textstr, " ")[[1]]
 line.height <- strheight("hy", cex = cex) * (1 + leading)
 x.len <- diff(x)
 y.pos <- y
 x.pos <- x[1]
 curword <- 1
 while (curword <= length(words)) {
  curline <- ""
  curline <- paste(curline, words[curword])
  curword <- curword + 1
  while (x.pos+strwidth(paste(curline,words[curword]),cex=cex) < x[2] &&
   !is.na(words[curword])) {
   curline<-paste(curline,words[curword])
   curword<-curword+1
  }
  text(x.pos,y.pos,curline)
  y.pos<-y.pos-line.height
 }
 if(box) rect(x[1],y+line.height,x[2],y.pos)
 par(adj=0.5)
}