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))
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