R-使用strwidth()测量字符串的宽度

问题描述 投票:0回答:1

我正在寻找帮助,以使用strwidth来测量以英寸为单位的字符串的宽度。如何指定字体和字体大小? (例如Times New Roman中的“ ABC%”或“ ABIi%”,字体大小为11)

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

strwidth("ABIi%", family="Times New Roman", units="inches")
r ggplot2
1个回答
0
投票

[我认为您的问题源于R无法识别字体。假设您使用的是Windows计算机,请按如下所示初始化字体。然后运行strwidth

windowsFonts("Times New Roman" = windowsFont("Times New Roman")) #initialize font first
strwidth("ABC%", family = "Times New Roman", units = "inches")
[1] 0.46875
© www.soinside.com 2019 - 2024. All rights reserved.