user12582271
user12582271

Reputation: 101

How to subscript/superscript and italicize x-axis labels?

I am trying to re-name the x-axis labels and would like to subscript/superscript few letters and numbers. For example, In FG(5,6)a I would like to italicize 'F' and would like to subscript/superscript 'a'. Likewise, I would like superscript/subscript and italicize '2' in KA(2,3)2, and a in LS(5,6)ab. Is there a way I can do this in R? Here is my code and output figure:

p <- ggbarplot(my_data_stack, x = "ind", y = "values", color = "ind", fill = "ind", 
                palette =c("blue", "green", "orange", "red", "black", "yellow"),
                width = 0.4, add = c("mean_se"))
p                
p +  scale_x_discrete(labels=c("a" = "SO", "b" = "KA(2,3)2", "c" = "FG(5,6)2", "d" = "FG(5,6)a", "e" = "LS(5,6)ab",
                                     "f" = "FG(1,5)f"))

enter image description here

Upvotes: 1

Views: 931

Answers (1)

Kreuni
Kreuni

Reputation: 312

You can add subscripts/superscripts using expression(). Subscripts use [] and superscripts ^.

So: "KA(2,3)2": expression("KA"["2,3"]^2)

Since there is a comma in the (2,3) you need to put it in quotes (or you can add the comma separately: [2*","*3]

Upvotes: 2

Related Questions