EVOLUTION-MANAGER
Edit File: strwidth.html
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><title>R: Plotting Dimensions of Character Strings and Math Expressions</title> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <link rel="stylesheet" type="text/css" href="R.css" /> </head><body> <table width="100%" summary="page for strwidth {graphics}"><tr><td>strwidth {graphics}</td><td style="text-align: right;">R Documentation</td></tr></table> <h2>Plotting Dimensions of Character Strings and Math Expressions</h2> <h3>Description</h3> <p>These functions compute the width or height, respectively, of the given strings or mathematical expressions <code>s[i]</code> on the current plotting device in <em>user</em> coordinates, <em>inches</em> or as fraction of the figure width <code>par("fin")</code>. </p> <h3>Usage</h3> <pre> strwidth(s, units = "user", cex = NULL, font = NULL, vfont = NULL, ...) strheight(s, units = "user", cex = NULL, font = NULL, vfont = NULL, ...) </pre> <h3>Arguments</h3> <table summary="R argblock"> <tr valign="top"><td><code>s</code></td> <td> <p>a character or <a href="../../base/html/expression.html">expression</a> vector whose dimensions are to be determined. Other objects are coerced by <code><a href="../../grDevices/html/as.graphicsAnnot.html">as.graphicsAnnot</a></code>.</p> </td></tr> <tr valign="top"><td><code>units</code></td> <td> <p>character indicating in which units <code>s</code> is measured; should be one of <code>"user"</code>, <code>"inches"</code>, <code>"figure"</code>; partial matching is performed.</p> </td></tr> <tr valign="top"><td><code>cex</code></td> <td> <p>numeric <b>c</b>haracter <b>ex</b>pansion factor; multiplied by <code><a href="par.html">par</a>("cex")</code> yields the final character size; the default <code>NULL</code> is equivalent to <code>1</code>.</p> </td></tr> <tr valign="top"><td><code>font, vfont, ...</code></td> <td> <p>additional information about the font, possibly including the graphics parameter <code>"family"</code>: see <code><a href="text.html">text</a></code>.</p> </td></tr> </table> <h3>Details</h3> <p>Note that the ‘height’ of a string is determined only by the number of linefeeds (<code>"\n"</code>) it contains: it is the (number of linefeeds - 1) times the line spacing plus the height of <code>"M"</code> in the selected font. For an expression it is the height of the bounding box as computed by <a href="../../grDevices/html/plotmath.html">plotmath</a>. Thus in both cases it is an estimate of how far <b>above</b> the final baseline the typeset object extends. (It may also extend below the baseline.) The inter-line spacing is controlled by <code>cex</code>, <code><a href="par.html">par</a>("lheight")</code> and the ‘point size’ (but not the actual font in use). </p> <p>Measurements in <code>"user"</code> units (the default) are only available after <code><a href="frame.html">plot.new</a></code> has been called – otherwise an error is thrown. </p> <h3>Value</h3> <p>Numeric vector with the same length as <code>s</code>, giving the estimate of width or height for each <code>s[i]</code>. <code>NA</code> strings are given width and height 0 (as they are not plotted). </p> <h3>See Also</h3> <p><code><a href="text.html">text</a></code>, <code><a href="../../base/html/nchar.html">nchar</a></code> </p> <h3>Examples</h3> <pre> 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 mean(sw.i / strwidth(str.ex, "fig")) / par('fin')[1] # = 1: are the same ## 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 (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 </pre> <hr /><div style="text-align: center;">[Package <em>graphics</em> version 3.6.0 <a href="00Index.html">Index</a>]</div> </body></html>