Skip to content

Variable Name Modification  #3

Open
@bromanje

Description

@bromanje

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions