Description Usage Arguments Value Note Author(s) References See Also Examples
Get width and height of (un-)rotated character strings for plotting with text
, etc.
1 | string.dim(s, cex = NULL, font = NULL, srt = 0)
|
s |
a character or |
cex |
numeric character expansion factor; multiplied by |
font |
the font to be used: see |
srt |
numeric, the string rotation in degrees. |
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.
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.
Christoph Heibl
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
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")
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.