Skip to content

Variable Name Modification #3

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
bromanje opened this issue Nov 21, 2024 · 0 comments
Open

Variable Name Modification #3

bromanje opened this issue Nov 21, 2024 · 0 comments

Comments

@bromanje
Copy link

I would like to modify PCA variable names in ggbiplot such that there can be Greek characters and sub-superscripts. I have included the data and here is what I have worked through so far.
rename_pca_var.csv

library(ggplot)
library(ggbiplot)
### Read in Data
data.example <- read.csv("rename_pca_var.csv")
head(data.example)
### removing categorical data. Running the PCA.
pca.example <- prcomp(data.example[,-c(1:6)],
                      center = TRUE,
                      scale. = TRUE)
## Plotting PCA
ggbiplot(pca.example,
         obs.scale = 1,
         var.scale = 1,
         varname.size = 5, 
         labels.size=3,
         groups = data.example$treatment,
         ellipse = TRUE,
         ellipse.alpha = 0.1,
         circle = FALSE,
         ellipse.prob = 0.68,
         varname.adjust= 1.5,
         inherit.aes = FALSE,
         repel = TRUE,
         scale = 0,
         parse = TRUE)

I would like to be able to update the PCA variables from "Phi" to Greek letters and be able to alter some of the text to subscripts and superscripts. Normally this could be done using supplying a variable with expression(Phi ["PSII"]) which would produce the Greek symbol and subscript PSII.

### A partial fix
pca.example.name_change <- pca.example

rownames(pca.example.name_change$rotation) <- c(expression("\u03A6 PSII"),expression("\u03A6 NO"),expression("\u03A6 NPQ"), "SPAD", expression("vH+"), "qE", "qT", "qI")


ggbiplot(pca.example.name_change,
         obs.scale = 1,
         var.scale = 1,
         varname.size = 5, 
         labels.size=3,
         groups = data.example$treatment,
         ellipse = TRUE,
         ellipse.alpha = 0.1,
         circle = FALSE,
         ellipse.prob = 0.68,
         varname.adjust= 1.5,
         inherit.aes = FALSE,
         repel = TRUE,
         scale = 0,
         parse = TRUE)

This is able to solve the issue of Greek letters but not the issue of printing sub-superscripts. Is there a way to add a variable to the ggbiplot function that could update the names of the variables, including the standard expression functionality in a similar way one may update variables in a legend? ie


ggbiplot(pca.example.name_change,
         varname.update = c(expression(Phi ["PSII"]),expression(Phi ["NO"]),expression(Phi ["NPQ"]), "SPAD", expression(vH^"+"), "qE", "qT", "qI")), ### This Would be the modification ###
         obs.scale = 1,
         var.scale = 1,
         varname.size = 5, 
         labels.size=3,
         groups = data.example$treatment,
         ellipse = TRUE,
         ellipse.alpha = 0.1,
         circle = FALSE,
         ellipse.prob = 0.68,
         varname.adjust= 1.5,
         inherit.aes = FALSE,
         repel = TRUE,
         scale = 0,
         parse = TRUE)

I believe my current solution is sufficient for what I am doing but feel there may be other individuals who would appreciate the full functionality of expression() in ggbiplot.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant