如何在标签或图例中未使用的R中逐字打印上标? [英] How to literally print superscripts in R not used in labels or legends?

查看:163
本文介绍了如何在标签或图例中未使用的R中逐字打印上标?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道在一个图中,可以使用expression()包括上标,例如

I know that in a graph one can use expression() to include superscripts, e.g.

plot(rnorm(20), xlab = expression(paste("n"^"th")))

但是,我实际上是想打印出上标,因此以后可以将它们存储在rtf文件中.实际上,我想用它们来表示与我的回归系数相关的统计显着性程度(您知道,例如"0.24 ^ *").

However, I literally want to print out superscripts, so I can store them in rtf files later. In fact, I want to use them to indicate the degree of statistical significance associated with my regression coefficients (you know, like "0.24^*").

使用"expression(paste("n"^"th"))",我尝试了print()cat()eval()get(),但是它们都不起作用.

With "expression(paste("n"^"th"))", I tried print(), cat(), eval(), and get() but none of them worked.

我当前正在使用"rtf"包输出".doc"文件.如果有人建议使用其他方式/软件包,则R本身不能在控制台中显示丰富格式也可以,但是无论如何结果都可以存储在某些文件中.

I am currently using the "rtf" package to output ".doc" files. If someone suggests using other ways/packages, it is OK if R itself cannot display rich formats in the console, but the results can be stored in some files anyway.

推荐答案

如您所见,?plotmath表达式仅在绘图中起作用. R中的任何内容都没有针对rtf输出进行优化.

As you've seen, the ?plotmath expressions only work within plots. Nothing in R is optimized for rtf output.

但是,阅读RTF插图后,很明显,您可以在输出中输入 rtf命令是用于上标的命令.试试

But reading the RTF vignette, it's clear you can write rtf commands in your output and there is a command for superscripting. Try

library(rtf)

rtf<-RTF("text.doc")
addText(rtf,"Hello\n")
addText(rtf,"0.05{\\super*}\n")
addText(rtf,"0.15*\n")
addText(rtf,"End")
done(rtf)

这篇关于如何在标签或图例中未使用的R中逐字打印上标?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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