1

I am looking for help to measure the width of the string in inches using strwidth. How should I specify font and size of font? (e.g. "ABC%" or "ABIi%" in Times New Roman and font size 11)

strwidth("ABC%", family="Times New Roman", units="inches")

strwidth("ABIi%", family="Times New Roman", units="inches")
hmhensen
  • 2,974
  • 3
  • 22
  • 43
R007
  • 101
  • 1
  • 13
  • Welcome! Please read https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example on how to ask reproducible questions. – hmhensen Jan 04 '20 at 00:27
  • I just edited content. I found that strwidth() might be helpful. I need help to specify font and size of font. – R007 Jan 04 '20 at 00:47

1 Answers1

2

I think your problems stem from R not recognizing the font. Assuming you're on a Windows machine, initialize your font as below. Then run strwidth.

windowsFonts("Times New Roman" = windowsFont("Times New Roman")) #initialize font first
strwidth("ABC%", family = "Times New Roman", units = "inches")
[1] 0.46875
hmhensen
  • 2,974
  • 3
  • 22
  • 43
  • great thanks worked. I have two questions...1) How can I specify font size? 2) How can I initialize font on Linux? – R007 Jan 04 '20 at 01:05
  • Sorry, not sure I can help much more. I don't have a Linux machine to test on. Try the `extrafonts` package. On the font size, seems like it might be complicated. See https://stackoverflow.com/questions/4241798/how-to-increase-font-size-in-a-plot-in-r. It's linked to the `cex` argument. – hmhensen Jan 04 '20 at 01:56