Add superscripts and subscripts to plotreg variable labels

112 views Asked by At

I'm wondering how to tweak plotreg()'s gl() function (it's function from the texreg package) to accommodate variables labels that contain super- or sub-scripts?

I've experimented with expression() and paste() but to no avail. I provide a working example (from their documentation) at below:

# install.packages("texreg")
library(texreg)

ctl <- c(4.17, 5.58, 5.18, 6.11, 4.50, 4.61, 5.17, 4.53, 5.33, 5.14)
trt <- c(4.81, 4.17, 4.41, 3.59, 5.87, 3.83, 6.03, 4.89, 4.32, 4.69)
group <- gl(2, 10, 20, labels = c("Ctl", "Trt")) # need to tweak this part
# for example, Ctl^2, Trt[2]
weight <- c(ctl, trt)
lm.D9 <- lm(weight ~ group)
lm.D90 <- lm(weight ~ group - 1)
plotreg(lm.D9) # plot model output as a diagram

1

There are 1 answers

1
Henry Holm On BEST ANSWER

Here is how to change the axis labels with ggplot2.

library(ggplot2)

g <- plotreg(lm.D90)

labs <- c(expression(Ctl^2),expression(Trt[2]))

g <- g + scale_x_discrete(labels = labs)

Ouput