r - R Graph - 图形字符串测量
问题描述
我想以图形方式测量字符串的宽度。(参见附图中的示例。我使用的是 Times New Roman,点大小为 11 和大小为 16)
每个字符将具有不同的宽度,例如相同字体和字体大小的“a”与“A”。我正在尝试寻找以图形方式绘制文本并以编程方式测量图形长度(以“mm”或“inch”表示)的解决方案,我尝试了 strwidth() 函数,但它无法正常工作。例如,“a”与“A”的值相同
解决方案
看起来您需要par()
与ps
参数一起使用。
strwidth("This is a test.", units = "inches", family = "Arial", ps = par(ps = 11))
[1] 0.875
> strwidth("This is a test.", units = "inches", family = "Arial", ps = par(ps = 16))
[1] 1.333333
> strwidth("This is a test.", units = "inches", family = "Times New Roman", ps = par(ps = 16))
[1] 1.145833
> strwidth("This is a test.", units = "inches", family = "Times New Roman", ps = par(ps = 11))
[1] 0.8333333
> strwidth("This is a test.", units = "inches", family = "Times New Roman", ps = par(ps = 24))
[1] 1.75
谷歌文档中的快速测量,它看起来很正确。
推荐阅读
- python - 二维数组python中的邻居
- python - 如何删除命令行缓冲
- reactjs - 如何从功能组件 React 中的 react-select 中获取价值
- django - Django - 分页
- arrays - 动态助手列?
- javascript - 意外使用“事件”获取图标的值。(反应JS)
- c++ - 模板化 c 字符串包装器中的大小扣除
- python - 在json的两个视图之间切换的正确方法是什么?
- javascript - 尝试从路由中删除一些代码以将其放入服务时遇到问题 - Node.js / Express.js
- firebase - 如何在 Flutter/Firestore 中实现先进先出系统?