View source: R/strwidth2xlim.R
strwidth2xlim | R Documentation |
Calculates the x-axis limits when adding (long) labels to a plot
strwidth2xlim(x, xstring, pos = 4, offset = 0.5, ...)
x |
numeric vector of horizontal coordinates |
xstring |
character vector, specifying text to be written |
pos |
position specifier for text; values of |
offset |
offset of the label from the coordinate in fractions of a character width |
... |
additional text parameters from |
See text
for details on pos
and offset
.
Minimum and maximum x-axis limits for adding horizontal text
Aimee Teo Broman
graphics::text()
x <- runif(15,-1,1)*10
xlabs <- sapply(sample(1:20,15,replace=TRUE),
function(a) paste(LETTERS[1:a], collapse=""))
## Labels to the left ##
xlims <- strwidth2xlim(x,xlabs,pos=2)
plot(x,1:length(x),xlim=xlims)
text(x,1:length(x),xlabs,pos=2)
## Labels to the right ##
xlims <- strwidth2xlim(x,xlabs,pos=4,cex=0.7)
plot(x,1:length(x),xlim=xlims)
text(x,1:length(x),xlabs,pos=4,cex=0.7)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.