0

I have a following code that generates a ggplot:

ggplot(data = t, aes(x = grp, y = b.hat, group = geo.l)) + 
          geom_hline(yintercept = unique(temp$b), lty='dotted', color = 'gray20') +
          geom_point(aes(color = geo.l), 
                     position = position_dodge(width = 1)) +
          geom_errorbar(aes(ymin = b.hat - 2 * b.hat.se, ymax = b.hat + 2 * b.hat.se, color = geo.l), 
                        alpha = 0.75, width = 0, 
                        position = position_dodge(width = 1)) +
          labs(x = '', y = "Estimates") +
          scale_color_manual(name = "Threshold", 
                             values = c('skyblue3', 'royalblue3', 'navyblue')) +
          facet_wrap(~sn, labeller = label_parsed) +
          theme_classic() +
          theme(legend.position = "bottom",
                axis.text.x = element_text(angle = 90, vjust = 0.5, hjust = 1),
                panel.grid.major  = element_blank(),
                panel.grid.minor  = element_blank(),
                plot.title  = element_blank(), 
                panel.border = element_rect(colour = "black", fill=NA, size=0.5))

ggplot

I'd like the texts along the x-axis to be shown similar to the facet labels (i.e., subscripts of the numbers). I tried it with

grp  <- unique(temp[,c('b.g.l', 'b.g.l.se', 'b.g.h', 'b.g.h.se')])

lab  <- c("list(U['[0.45,0.55]'] , U['[0.2,0.3]'])" = 
                   expression(paste("list(U['[", grp$b.g.l[1] - grp$b.g.l.se[1], ",", grp$b.g.l[1] + grp$b.g.l.se[1], "]']", ' , ',
                                    "U['[", grp$b.g.h[1] - grp$b.g.h.se[1], ",", grp$b.g.h[1] + grp$b.g.h.se[1], "]'])")),
                   "list(U['[0.45,0.55]'] , U['[0.45,0.55]'])" = 
                     expression(paste("list(U['[", grp$b.g.l[2] - grp$b.g.l.se[2], ",", grp$b.g.l[2] + grp$b.g.l.se[2], "]']", ' , ',
                                      "U['[", grp$b.g.h[2] - grp$b.g.h.se[2], ",", grp$b.g.h[2] + grp$b.g.h.se[2], "]'])")),
                   "list(U['[0.7,0.8]'] , U['[0.2,0.3]'])" = 
                     expression(paste("list(U['[", grp$b.g.l[3] - grp$b.g.l.se[3], ",", grp$b.g.l[3] + grp$b.g.l.se[3], "]']", ' , ',
                                    "U['[", grp$b.g.h[3] - grp$b.g.h.se[3], ",", grp$b.g.h[3] + grp$b.g.h.se[3], "]'])")),
                   "list(U['[0.7,0.8]'] , U['[0.45,0.55]'])" = 
                     expression(paste("list(U['[", grp$b.g.l[4] - grp$b.g.l.se[4], ",", grp$b.g.l[4] + grp$b.g.l.se[4], "]']", ' , ',
                                      "U['[", grp$b.g.h[4] - grp$b.g.h.se[4], ",", grp$b.g.h[4] + grp$b.g.h.se[4], "]'])")))

and add scale_x_discrete(labels = lab) based on the answer here but it returns an error

Error: Continuous value supplied to discrete scale

Could someone help figure out how to invoke special letters in the x-axis text in ggplot?

The data can be found here

Dai
  • 51
  • 5
  • It's easier to help you if you include a simple [reproducible example](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) with sample input that can be used to test and verify possible solutions. Data should be include in the question and not stored on an external site. There seems to be a bunch of formatting code not directly related to this problem. Make sure to simplify your example as much as possible when asking for help so it's easier to focus on the problem at hand. – MrFlick Nov 10 '21 at 01:56
  • I had a similar question, answered here: https://stackoverflow.com/questions/72343955/adding-greek-symbol-and-superscript-to-ggplot-axis-text-tickmarks/72344123#72344123 – mlcyo May 23 '22 at 06:38

0 Answers0