r - 在 R 中使用 bquote 的上标之后的下标

标签 r

我正在尝试绘制一个特定的 R 平方度量,即相对于 1:1 线的 R2。以下是一些生成数据和绘图的代码。 (我意识到我只是在这里计算标准 r 平方,但这对于计算代码来说没问题)。

#generate data.
set.seed(1234)
x <- rnorm(100)
y <- x*0.7 + rnorm(100)
mod <- lm(y~x)

#develop rsq label.
rsq <- round(summary(mod)$r.squared, 2)
rsq.1.lab <- bquote(R^2 [1:1] == .(rsq))

#drop plot and rsq label.
plot(y ~ x)
mtext(rsq.1.lab, side = 3, line = -2, adj = 0.05)

情节如下: enter image description here

这非常接近,但下标实际上是相对于上标的,而不是相对于字母 R 的。我该如何更改它?寻找使用基本 R 的解决方案,最好保留 bquote()

最佳答案

使用{/}分组:

rsq.1.lab <- bquote({R^2} [1:1] == .(rsq))

option 1

rsq.1.lab <- bquote({R [1:1]}^2 == .(rsq))

option 2

甚至有点可笑

rsq.1.lab <- bquote(R * atop(2, "1:1") == .(rsq))

option 3

虽然我们可以使用稍微减小字体大小

rsq.1.lab <- bquote(R * scriptstyle(atop(2, "1:1")) == .(rsq))

option 4

其中大部分建议/记录在 ?plotmath 中.

关于r - 在 R 中使用 bquote 的上标之后的下标,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59938064/

相关文章:

r - 按月份和年份对组进行排序

r - 使用 read.table 并重命名列名

根据 R 中的值从矩阵返回列名称

R:并行 makePSOCKcluster 挂起

r - R 中 nlme 包中的 gls 函数出错

从 lapply 返回匿名函数 - 出了什么问题?

regex - 如何使用删除字符向量内单词之间的多余空白?

r - 将 data.table 中的列表分配/提取值到列

r - 如何使 'head'自动应用于输出?

r - 简化代码以根据另一个变量的分箱更有效地获取两个变量的平均值