I need change the labels with custom labels that are not in the data because I want to introduce some latex formulas in the labels.
To illustrate the issue I will use an example I copied from https://www.r-graph-gallery.com/48-grouped-barplot-with-ggplot2.
# library
library(ggplot2)
library(latex2exp)
# create a dataset
specie <- c(rep("sorgho" , 3) , rep("poacee" , 3) , rep("banana" , 3) , rep("triticum" , 3) )
condition <- rep(c("normal" , "stress" , "Nitrogen") , 4)
value <- abs(rnorm(12 , 0 , 15))
data <- data.frame(specie,condition,value)
# Grouped
ggplot(data, aes(fill=condition, y=value, x=specie)) +
geom_bar(position="dodge", stat="identity")
This example produces the following plot:
Instead of the labels Nitrogen
, normal
, and stress
, I want to use latex formulas as TeX('$\\alpha^2$')
, TeX('$\\beta^3$')
and TeX('$\\alpha+\\beta$')
. Of course, I prefer to modify the plot, but not the data. How can I do it?