1
votes

I am trying to create a biplot but my labels are chemical formulas that need subscript for example: NO3 should be NO subscript 3 superscript -. How can I get the subscript in the labels for the column names on a biplot?

library("FactoMineR")
library("ggplot2")

Site <- c("site1", "site2", "site3")
NO3 <- c(100, 300, 200)
NH4 <- c(210, 400, 800)
DON <- c(300, 350, 200)

dat <- cbind(NO3, NH4, DON)
data.frame(dat)
rownames(dat)<- Site


res.pca <- PCA(dat, scale.unit = TRUE, ncp = 4, graph = TRUE)
print(res.pca)
1
hacky way: PCA returns a ggplot object, so you can just add more layers: plot.PCA(res.pca, choix = 'var', label = 'none') + geom_text(aes(label = c('NO[3]', 'NH[4]', 'DON')), parse = TRUE)rawr
@rawr when I do that, the response is "NULL"KerryLee
are you using the example in your question or on your actual data?rawr
example in the questionKerryLee
Got it when I changed to R version 4.0, thanks!KerryLee

1 Answers

0
votes

You can use the R function expression, e.g.

plot(x, y, main=expression('NO'[3]))