如何在 R 中的绘图中添加破折号?
我正在 R 中创建一个绘图,并且需要向某些轴标签添加一个破折号,而不是日常的连字符。
axis(1, at=c(0:2), labels=c("0-10","11-30","31-70"))
我在 Linux 上运行 R 版本 2.8.1。
I'm creating a plot in R, and need to add an en dash to some axis labels, as opposed to your everyday hyphen.
axis(1, at=c(0:2), labels=c("0-10","11-30","31-70"))
I'm running R version 2.8.1 on Linux.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
老问题但仍然是一个问题...
我在 OSX 10.12.2 上使用 R vsn 3.3.2,使用plot()绘制到导入到 Affinity Designer vsn 1.5.4 中的 pdf 文件。 “2-0”形式的轴标签显示在 Affinity Designer 中,其中破折号与“0”重叠。我不知道问题是否出在 Affinity Designer 或 pdf 文件上还是什么。如果能够尝试各种 Unicode 破折号字符,那就太好了,但是 R 和 pdf 文件似乎都还没有完全具备使用默认字体处理 Unicode 的能力。
解决方案:R 中的“cairo”包:
破折号显示在 R 控制台、默认 R 绘图设备以及使用 Preview 和 Affinity Designer 查看的 pdf 文件中。
Old question but still a problem...
I'm using R vsn 3.3.2 on OSX 10.12.2, plotting with plot() to a pdf file that I import into Affinity Designer vsn 1.5.4. Axis labels of the form "2-0" show up in Affinity Designer with the dash overlapping the "0". I don't know if the problem lies with Affinity Designer or the pdf file or what. It would be nice to be able to try various Unicode dash characters, but R and pdf files both seem to not yet be fully equipped to deal with Unicode using the default fonts.
Solution: the "cairo" package in R:
The dashes show up in the R console, default R plotting device, and the pdf file viewed with both Preview and Affinity Designer.
在此示例中,您可以使用
expression()
函数来正确渲染短划线:In this example, you can use the
expression()
function to get en dashes rendered properly:您使用的是 Linux,因此根据 R 对 unicode 的理解程度,您可以将备用键盘键之一映射到 撰写密钥,然后将其键入即可。要获得 —,请按 Compose,然后按正常的 - 键两次或三次(具体取决于系统的映射)。请注意,使用撰写键时,您不必按住它 - 只需按顺序按下按键即可。
具体启用方式有所不同,但在 Ubuntu 中,系统 -> 首选项 -> 键盘、布局选项卡、布局选项按钮,然后选择适合“撰写键位置”项目的内容。我通常使用菜单键。
编辑:我的错误,你想要一个短破折号,而不是一个长破折号。那么 en-dash (–) 是 Compose dash 破折号句点,而不是 Compose dash 破折号。
You're using Linux, so depending on how well R understands unicode, you could map one of your spare keyboard keys to the Compose Key and then just type it out. To get a —, press Compose and then the normal - key two or three times (depending on your system's mappings). Note that when using the Compose key, you don't hold it down - just press the keys in sequence.
Exactly how you'd enable that varies, but in Ubuntu, System->Preferences->Keyboard, Layout tab, Layout Options button, and select something appropriate for the "Compose key position" item. I usually use the Menu key.
Edit: My mistake, you wanted an en-dash, not an em-dash. Then en-dash (–) is Compose dash dash period, rather than Compose dash dash dash.
MDPI 日志请求将轴标签中的连字符更改为短划线。
使用图形的基本系统,我通过简单地将“-”更改为不带空格的“\u2013”来解决问题。完整形式的 axis 示例代码为
axis(1,1:2,c("20\u201329","40\u201349")
在我的例子中,两个标签表示两个年龄组。我在 R 4.1.3 和 windows 10 中使用它。
a MDPI journal has requested to change from hyphen to en dash in the axis labels.
Using the base system for graph, I solved the problem by simply changing the "-" with "\u2013" without spaces. The example code for axis in a complete form is
axis(1,1:2,c("20\u201329","40\u201349")
In my case the two labels expressed two age groups. I used it in R 4.1.3 and windows 10.