I have a character vector which contains Greek letters.
labNames <- c("rho x alpha", "z x rho", "beta x rho")
I want to see these labels on X axis, referring to the object labNames. The result must be as if I used expression(rho x alpha). Typing expression(labNames[1]) is wrong, but I'm not able to figure out how to solve it. Please look at the following example:
plot(c(2,5,8), 1:3, axes=F, pch=19, xlab="", ylab="")
axis(2, 1:3, labels = c(expression(labNames[1]), expression(labNames[2]), expression(labNames[3])), las=2, tck = FALSE, lty = 0)
You need to format the expressions properly:
labNames <- c("rho x alpha", "z x rho", "beta x rho")
labNames <- gsub(' ', '~', labNames)
and then you can use parse
plot(c(2,5,8), 1:3, axes=F, pch=19, ann = FALSE)
axis(2, 1:3, labels = parse(text = labNames), las=2, tck = FALSE, lty = 0)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With