Hello,

I need to add some text to a plot and I would like this text to be of a
given width in user coordinates.

I know I can get the width of a string for a given cex using strwidth. But
how can I do the other way around? How can I get the cex value that will
make my string of a given width (at least approximately)?

In this example I want my string to have width 50 so the 'target' cex would
be 1.5, at least on my device:

mytext<- 'Text to shrink or expand'
text_width<- 50
pdf()
plot(0, xlim= c(0, 100), ylim= c(0, 100))
strwidth(mytext, units= 'user', cex= 1)   ## Too small
#[1] 33.00625
strwidth(mytext, units= 'user', cex= 2)   ## Too big
#[1] 66.0125
strwidth(mytext, units= 'user', cex= 1.5) ## About right
#[1] 49.50937
dev.off()

Thanks!
Dario

	[[alternative HTML version deleted]]

