5

Is it at all possible to calculate the width size (in inches) of a particular string in the default font ( par()$family ) , and default size ( par()$ps ).

Calculating the height seems relatively simple:

par()$ps * 1/72

The challenge with width is that it is dependent on the string itself. A string of i's "iiiiii" is smaller than a string of o's "ooooooo"

Suraj
  • 35,905
  • 47
  • 139
  • 250

1 Answers1

7

You are looking for the function strwidth in base

strwidth('this is cool', font = 12, units = 'in')
Ramnath
  • 54,439
  • 16
  • 125
  • 152
  • 1
    +1 Exactly so. See also the "Health Warning" Andrie included in [his answer](http://stackoverflow.com/questions/7730150/extent-of-boundary-of-text-in-r-plot/7730492#7730492) to a similar question. – Josh O'Brien Dec 15 '11 at 21:49
  • Is there a reason why strheight("A",font=16,units="in") returns .18 and not .22 according to the formula I posted? – Suraj Dec 15 '11 at 21:54
  • see the link in Josh's comment. It is a function of what your current graphics setting is. – Ramnath Dec 15 '11 at 21:58
  • I'm in the browser and strheight is returning .15. par()$ps is 16. Is my equation wrong? – Suraj Dec 15 '11 at 22:00