R Graph-图形化字符串测量 [英] R Graph - graphical string measurement

查看:75
本文介绍了R Graph-图形化字符串测量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想以图形方式测量字符串的宽度. (请参见附件中的示例.我使用的是Times New Roman,其磅值分别为11和16).

I would like to graphically measure the width of a string. (see examples in the attached image. I have used Times New Roman with point size 11 and size 16)

每个字符的宽度都不同,例如"a"与"A"对于相同的字体&字体大小.我正在尝试寻找以图形方式绘制文本并以编程方式测量图形长度(以"mm"或"inch"为单位)的解决方案 我尝试了strwidth()函数,但无法正常工作.例如给我"a"的相同值与"A"

Each character will have different width e.g. "a" vs "A" for the same font & font size. I am trying to look for solution to graphically plot text and programmatically measure the graphical length (in terms of "mm" or "inch") I tried strwidth() function but it is not working correctly. e.g. gives me same value for "a" vs "A"

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

推荐答案

您似乎需要将par()ps参数一起使用.

It looks like you'll need to use par() with the ps argument.

 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

一种快速的Google文档测量方法,看起来很正确.

A quick measure in a google doc, and it looks about right.

这篇关于R Graph-图形化字符串测量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆