[英]subscript after superscript using bquote in R
I am trying to plot a specific R-square metric, the R2 relative to the 1:1 line.我正在尝试绘制一个特定的 R 平方指标,即相对于 1:1 线的 R2。 Here are some code to generate data and a plot.
下面是一些生成数据和绘图的代码。 (I realize I am only calculating standard r-squared here, but thats fine for the purposes of working out the code).
(我意识到我只是在这里计算标准 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)
The plot looks like this:情节是这样的:
This is pretty close, but the subscript is actually relative to the superscript, rather than being relative to the letter R. How can I change this?这非常接近,但下标实际上是相对于上标的,而不是相对于字母 R。我该如何更改? Looking for solutions that use base R, ideally keeping
bquote()
.寻找使用基础 R 的解决方案,最好保留
bquote()
。
Use {
/ }
grouping:使用
{
/ }
分组:
rsq.1.lab <- bquote({R^2} [1:1] == .(rsq))
or或者
rsq.1.lab <- bquote({R [1:1]}^2 == .(rsq))
or even a somewhat ridiculous甚至有点可笑
rsq.1.lab <- bquote(R * atop(2, "1:1") == .(rsq))
though we can reduce the font size a little using虽然我们可以使用
rsq.1.lab <- bquote(R * scriptstyle(atop(2, "1:1")) == .(rsq))
Much of this is suggested/documented in ?plotmath
. ?plotmath
建议/记录了其中的大部分?plotmath
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.