text function in R, how to get an idea of width? [Off Topic]
Hi all,
hot greetings from Ahmedabad.
Let's say I do this:
On my system (and it may indeed be dependent on various factors like devices, resolution, OS and a ton of stuff I know nothing about) I am getting the two labels printed with Arial in the rectangle, and while s1 fits inside the rectangle, s2 doesn't - it extends beyond the rectangle borders to the right.
So here's the challenge:
How can I determine dynamically if any text s2 fits inside the rectangle or not?
I have deliberately chosen not to use specify a fixed-width font family (Courier would otherwise be easy to set). Note also the "useKerning" option of the pdf function which may have some influence on actual text width.
Many thanks for any input.
EM.
hot greetings from Ahmedabad.
Let's say I do this:
foo=function(s1, s2)
{
pdf("foopdf1.pdf", height=4, width=3)
y=c(8,2,3,3,1,2,3,1,9)
barplot(y)
rect(2,4,8,6)
text(2,5, s1, pos=4)
text(2,4.3, s2, pos=4)
dev.off()
}
foo("Text is ok", "Text is too wide")
system2('open', args = 'foopdf1.pdf', wait = T)
On my system (and it may indeed be dependent on various factors like devices, resolution, OS and a ton of stuff I know nothing about) I am getting the two labels printed with Arial in the rectangle, and while s1 fits inside the rectangle, s2 doesn't - it extends beyond the rectangle borders to the right.
So here's the challenge:
How can I determine dynamically if any text s2 fits inside the rectangle or not?
I have deliberately chosen not to use specify a fixed-width font family (Courier would otherwise be easy to set). Note also the "useKerning" option of the pdf function which may have some influence on actual text width.
Many thanks for any input.
EM.
—
Pass or fail!
ElMaestro
Pass or fail!
ElMaestro
Complete thread:
- text function in R, how to get an idea of width?ElMaestro 2022-04-24 19:09
- Help is on the way Helmut 2022-04-24 22:24
- The width of text is important, not the rectangle ElMaestro 2022-04-25 04:20
- I suggest strwidth() Helmut 2022-04-25 09:26
- The width of text is important, not the rectangle ElMaestro 2022-04-25 04:20
- Help is on the way Helmut 2022-04-24 22:24