The R Project SVN R

Rev

Rev 61153 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 61153 Rev 61168
Line 55... Line 55...
55
\seealso{
55
\seealso{
56
  \code{\link{text}}, \code{\link{nchar}}
56
  \code{\link{text}}, \code{\link{nchar}}
57
}
57
}
58
\examples{
58
\examples{
59
str.ex <- c("W","w","I",".","WwI.")
59
str.ex <- c("W","w","I",".","WwI.")
60
op <- par(pty = 's'); plot(1:100, 1:100, type = "n")
60
op <- par(pty = "s"); plot(1:100, 1:100, type = "n")
61
sw <- strwidth(str.ex); sw
61
sw <- strwidth(str.ex); sw
62
all.equal(sum(sw[1:4]), sw[5])
62
all.equal(sum(sw[1:4]), sw[5])
63
#- since the last string contains the others
63
#- since the last string contains the others
64
 
64
 
65
sw.i <- strwidth(str.ex, "inches"); 25.4 * sw.i # width in [mm]
65
sw.i <- strwidth(str.ex, "inches"); 25.4 * sw.i  # width in [mm]
66
unique(sw / sw.i)
66
unique(sw / sw.i)
67
# constant factor: 1 value
67
# constant factor: 1 value
68
mean(sw.i / strwidth(str.ex, "fig")) / par('fin')[1] # = 1: are the same
68
mean(sw.i / strwidth(str.ex, "fig")) / par('fin')[1]  # = 1: are the same
69
 
69
 
70
## See how letters fall in classes
70
## See how letters fall in classes
71
##  -- depending on graphics device and font!
71
##  -- depending on graphics device and font!
72
all.lett <- c(letters, LETTERS)
72
all.lett <- c(letters, LETTERS)
73
shL <- strheight(all.lett, units = "inches") * 72 # 'big points'
73
shL <- strheight(all.lett, units = "inches") * 72  # 'big points'
74
table(shL) # all have same heights ...
74
table(shL)  # all have same heights ...
75
mean(shL)/par("cin")[2] # around 0.6
75
mean(shL)/par("cin")[2] # around 0.6
76
 
76
 
77
(swL <- strwidth(all.lett, units = "inches") * 72) # 'big points'
77
(swL <- strwidth(all.lett, units = "inches") * 72)  # 'big points'
78
split(all.lett, factor(round(swL, 2)))
78
split(all.lett, factor(round(swL, 2)))
79
 
79
 
80
sumex <- expression(sum(x[i], i=1,n), e^{i * pi} == -1)
80
sumex <- expression(sum(x[i], i=1,n), e^{i * pi} == -1)
81
strwidth(sumex)
81
strwidth(sumex)
82
strheight(sumex)
82
strheight(sumex)
83
 
83
 
84
par(op)#- reset to previous setting
84
par(op)  #- reset to previous setting
85
}
85
}
86
\keyword{dplot}
86
\keyword{dplot}
87
\keyword{character}
87
\keyword{character}