strwidth(graphics)
strwidth()所属R语言包:graphics
Plotting Dimensions of Character Strings and Math Expressions
绘制字符串和数学表达式尺寸
译者:生物统计家园网 机器人LoveR
描述----------Description----------
These functions compute the width or height, respectively, of the given strings or mathematical expressions s[i] on the current plotting device in user coordinates, inches or as fraction of the figure width par("fin").
这些函数计算的宽度或高度,分别给定的字符串或数学表达式,s[i]用户坐标,英寸或分数图的宽度par("fin")对当前的绘图设备。
用法----------Usage----------
strwidth(s, units = "user", cex = NULL, font = NULL, vfont = NULL, ...)
strheight(s, units = "user", cex = NULL, font = NULL, vfont = NULL, ...)
参数----------Arguments----------
参数:s
a character or expression vector whose dimensions are to be determined. Other objects are coerced by as.graphicsAnnot.
字符或表达向量,其尺寸为待定。其他对象被强制as.graphicsAnnot。
参数:units
character indicating in which units s is measured; should be one of "user", "inches", "figure"; partial matching is performed.
字符显示在单位s的测量;应该是一个"user","inches","figure";进行部分匹配。
参数:cex
numeric character expansion factor; multiplied by par("cex") yields the final character size; the default NULL is equivalent to 1.
数字字符膨胀系数乘以par("cex")产生的最后一个字符的大小,默认的NULL相当于1的。
参数:font, vfont, ...
additional information about the font, possibly including the graphics parameter "family": see text.
有关字体的其他信息,可能包括图形参数"family":看到text。
Details
详情----------Details----------
Note that the "height" of a string is determined only by the number of linefeeds ("\n") it contains: it is the (number of linefeeds - 1) times the line spacing plus the height of "M" in the selected font. For an expression it is the height of the bounding box as computed by plotmath. Thus in both cases it is an estimate of how far above the final baseline the typeset object extends. (It may also extend below the baseline.) The inter-line spacing is controlled by cex, par("lheight") and the "point size" (but not the actual font in use).
注意字符串的“高度”是唯一的换行符数量确定("\n"),它包含:(换行符数 - 1)倍行距加上"M"高度在选定的字体。一个表达式,它是由plotmath计算的边界框的高度。因此,在这两种情况下,它是一个估计最终基线以上的排版对象延伸。 (这也可能延长低于基准)。间行距控制cex,par("lheight")和点大小(而不是实际使用中的字体)。
Measurements in "user" units (the default) are only available after plot.new has been called – otherwise an error is thrown.
"user"单位(默认值)的测量仅可后plot.new被称为“ - 否则会抛出错误。
值----------Value----------
Numeric vector with the same length as s, giving the estimate of width or height for each s[i]. NA strings are given width and height 0 (as they are not plotted).
s相同的长度,宽度或高度为每个s[i]估计,数字矢量。 NA字符串的宽度和高度0(因为它们没有绘制)。
参见----------See Also----------
text, nchar
text,nchar
举例----------Examples----------
str.ex <- c("W","w","I",".","WwI.")
op <- par(pty='s'); plot(1:100,1:100, type="n")
sw <- strwidth(str.ex); sw
all.equal(sum(sw[1:4]), sw[5])
#- since the last string contains the others[ - 自上次字符串包含其他]
sw.i <- strwidth(str.ex, "inches"); 25.4 * sw.i # width in [mm][宽度[毫米]]
unique(sw / sw.i)
# constant factor: 1 value[常数因子:1值]
mean(sw.i / strwidth(str.ex, "fig")) / par('fin')[1] # = 1: are the same[= 1:是相同的]
## See how letters fall in classes[#请参阅字母类下降]
## -- depending on graphics device and font![# - 根据图形设备和字体!]
all.lett <- c(letters, LETTERS)
shL <- strheight(all.lett, units = "inches") * 72 # 'big points'[“大点”]
table(shL) # all have same heights ...[所有具有相同的高度......]
mean(shL)/par("cin")[2] # around 0.6[约0.6]
(swL <- strwidth(all.lett, units="inches") * 72) # 'big points'[“大点”]
split(all.lett, factor(round(swL, 2)))
sumex <- expression(sum(x[i], i=1,n), e^{i * pi} == -1)
strwidth(sumex)
strheight(sumex)
par(op)#- reset to previous setting[ - 恢复到以前的设置]
转载请注明:出自 生物统计家园网(http://www.biostatistic.net)。
注:
注1:为了方便大家学习,本文档为生物统计家园网机器人LoveR翻译而成,仅供个人R语言学习参考使用,生物统计家园保留版权。
注2:由于是机器人自动翻译,难免有不准确之处,使用时仔细对照中、英文内容进行反复理解,可以帮助R语言的学习。
注3:如遇到不准确之处,请在本贴的后面进行回帖,我们会逐渐进行修订。
|