0

My data code is:

df <- data.frame(
  group = c("NO", "H2O2"),
  values = c(10,11)
)

df %>% ggplot(aes(x=group, y=values))+ geom_col(width = 0.5)+
  theme_bw()

This plots a graph, like this:enter image description here

I want both '2' in H2O2 as subscripts. How can this be done?

M.R.Wani
  • 107
  • 1
  • 11
  • 3
    Does this answer your question? [how to subscript the x axis tick label](https://stackoverflow.com/questions/28978011/how-to-subscript-the-x-axis-tick-label) – A. S. K. Jan 08 '21 at 18:16
  • yes. It has answered my question. Thank you so much – M.R.Wani Jan 09 '21 at 03:28

1 Answers1

1

You can follow the example code from this answer

In your case...

library(ggplot2)
library(latex2exp)
df <- data.frame(
  group = c("NO", "H2O2"),
  values = c(10,11)
)

df %>% ggplot(aes(x=group, y=values))+ geom_col(width = 0.5) +
  scale_x_discrete(breaks = c("NO", "H2O2"),
                   labels = c("NO", parse(text=TeX("$H_2O_2$")))
                   ) +
  theme_bw()
krfurlong
  • 867
  • 6
  • 17