r - 如何在 R 中使用 mtext 函数修复文本
问题描述
我很难使用 mtext 修复我的情节中的文本
假设这是我的数据:
df<-rnorm(100,12,2)
使用的代码是:
plot(df)
mtext(col="red",side=3,line=1,at=39, paste(round(12,4)))
mtext('text here=',col="dark green", side=3, line=1, at=10)
当我使用这些代码时,'text here=' 和 '12' 的值之间存在差距。当我修复它时,当我在 Rstudio 中扩展绘图区域时,我会得到差距。
我想在这里有文本= 12,当我展开情节时,它不会改变。如果我们能简化代码就好了。
解决方案
您可以为此使用带有 bquote 的幻像表达式:
编辑:
要调整位置,请使用adj
和padj
。
df<-rnorm(100,12,2)
plot(df)
txt1 <- bquote(expression("text here = " * phantom(.(round(12,4)))))
txt2 <- bquote(expression(phantom("text here = ") * .(round(12,4))))
mtext(eval(txt1), col = "dark green", adj=0, padj=-1)
mtext(eval(txt2), col = "red", adj=0, padj=-1)
由reprex 包(v0.3.0)于 2020 年 3 月 28 日创建
推荐阅读
- rust - 从 rust 中的结构返回值 T
- python - Python - 创建 CSV 文件
- nginx - 如何使 nginx 仅侦听非本地 DHCP IP?
- python - 平方 X 张量流模型
- scala - 在资源文件夹下找不到文件
- javascript - 我什么时候使用函数借用?
- xcode - 使用 swiftUI 在 iOS 15 中创建共享表
- python - 如何将一维维度数组输入 numpy.random.randn?
- elasticsearch - 在 Elixir Phoenix 中保存/更新后在 Elasticsearch 中创建文档
- spring - 即使某些 serviceIds 的上传失败,如何继续将附件上传到多个(Ids - 例如:ServiceIds)服务