Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Calculate width of text string in default font/size

Tags:

r

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"

like image 542
SFun28 Avatar asked Dec 15 '11 21:12

SFun28


1 Answers

You are looking for the function strwidth in base

strwidth('this is cool', font = 12, units = 'in')
like image 133
Ramnath Avatar answered Sep 22 '22 00:09

Ramnath