1

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
Chris T.
  • 1,699
  • 7
  • 23
  • 45
  • 1
    '[' is a metacharacter. I think you may be looking into a lot of trouble trying to change the behavior on this one. Why not just create a customized function that inludes the super or subscripts as additional arguments? – GuedesBF Nov 07 '21 at 14:53
  • Are you looking for these sub/super scripts to appear in your plot output? i.e. 'groupCtl^2" appears with a superscript not as written here? – Henry Holm Nov 07 '21 at 21:17

1 Answers1

1

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

Henry Holm
  • 495
  • 3
  • 13
  • 1
    Many thanks, this is one neat solution. (Pardon me for my late reply. It appears that my earlier reply didn't show up in this thread, not sure what happened) – Chris T. Nov 08 '21 at 18:32