string.dim: Dimensions of Rotated Strings

Description Usage Arguments Value Note Author(s) References See Also Examples

Description

Get width and height of (un-)rotated character strings for plotting with text, etc.

Usage

1
string.dim(s, cex = NULL, font = NULL, srt = 0)

Arguments

s

a character or expression vector whose dimensions are to be determined. Other objects are coerced by as.graphicsAnnot.

cex

numeric character expansion factor; multiplied by par("cex") yields the final character size; the default NULL is equivalent to 1.

font

the font to be used: see par.

srt

numeric, the string rotation in degrees.

Value

a matrix with two named columns: x and y represent the width and the height of s in "user" units and correspond to the output of strwidth and strheight for unrotated plotting.

Note

Currently, string.dim can handle only horizontally (i.e. srt %in% c(0, 180)) and vertically (i.e. srt %in% c(90, 270)) plotted strings.

Author(s)

Christoph Heibl

References

The function is based on an e-mail exchange between Stephane Dray and Brian Ripley in November 2007: http://tolstoy.newcastle.edu.au/R/e3/help/07/11/3149.html

See Also

text, strwidth, strheight

Examples

 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
s <- "Axototl"
plot(x = c(0, 1), y = c(0, 2))

## horizontal
x <- .1; y <- .3
points(x, y, pch = 4, col = "red")
text(x, y, s, cex = 3, adj = c(0,0 ))
xy <- string.dim(s, cex = 3, srt = 0)
points(x + xy[, "x"], y, pch = 4, col = "blue")
points(x, y + xy[, "y"], pch = 4, col = "green")

## vertical
## remark: if using srt, adj still refers to the 
## dimensions like it did in the unrotated string
x <- .1; y <- .5
points(x, y, pch = 4, col = "red")
text(x, y, s, cex = 3, adj = c(0,1), srt = 90)
xy <- string.dim(s, cex = 3, srt = 90)
points(x + xy[, "x"], y, pch = 4, col = "blue")
points(x, y + xy[, "y"], pch = 4, col = "green")

## diagonal: does not yet work
x <- .4; y <- .7
points(x, y, pch = 4, col = "red")
text(x, y, s, cex = 3, adj = c(0,1), srt = 45)
xy <- string.dim(s, cex = 3, srt = 45)
points(x + xy[, "x"], y, pch = 4, col = "blue")
points(x , y + xy[, "y"], pch = 4, col = "green")

fmichonneau/phyloch documentation built on May 16, 2019, 1:45 p.m.