Reputation: 1935
I know that in a graph one can use expression() to include superscripts, e.g.
plot(rnorm(20), xlab = expression(paste("n"^"th")))
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^*").
With "expression(paste("n"^"th"))
", I tried print()
, cat()
, eval()
, and get()
but none of them worked.
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.
Upvotes: 1
Views: 1626
Reputation: 206167
As you've seen, the ?plotmath
expressions only work within plots. Nothing in R is optimized for rtf output.
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)
Upvotes: 4
Reputation: 1575
plot(rnorm(20), xlab = as.character("n^*"))
or even
plot(rnorm(20), xlab = paste0("n","^","th"))
Not sure why you want to use expression()
Upvotes: 0