Label size in plotLoadings

Hello,

I use PLSDA with metabolites that have a very long name.
In the loadings plot, these names are cut and I would like to find a solution to display them in full.
I tried to adjust the size.name parameter but it doesn’t resolve my problem.

With size.name = 0.5 :
plsda_ploadloadings_size05

In red, you can see where the name of the metabolite is cut.
Can you help me ?

Thanks a lot

Hi @hschrieke,

Thanks for using mixOmics.

If the feature names are too long, the plots can become too narrow. For example, if untrimmed, the following plot:

 data(nutrimouse)
    Y = nutrimouse$diet
    gene = nutrimouse$gene
    lipid = nutrimouse$lipid
    ## extend feature names
    suff <- "-a-long-suffix-from-abolutely-nowhere-which-is-gonna-be-longer-than-margins"
    colnames(gene) <- paste0(colnames(gene), suff)
    colnames(lipid) <- paste0(colnames(lipid), suff)
    data = list(gene = gene, lipid = lipid)
    design = matrix(c(0,1,1,1,0,1,1,1,0), ncol = 3, nrow = 3, byrow = TRUE)
    
    nutrimouse.sgccda = block.splsda(X = data,
                                     Y = Y,
                                     design = design,
                                     keepX = list(gene = c(10,10), lipid = c(15,15)),
                                     ncomp = 2,
                                     scheme = "centroid")
    plotLoadings(nutrimouse.sgccda, contrib = "min")

image

Even with one long feature name would run into margin errors or could look like the following (even if no errors occur):

That is why we decided to limit the length of feature names with a message that informs about the trimming. You can still access the full feature names by saving the output from plotLoadings.

pl_res <- plotLoadings(nutrimouse.sgccda, contrib = "min")
head(pl_res)

I just added a feature to the development version (which you can install using instruction in https://github.com/mixOmicsTeam/mixOmics#development-version) that allows you to adjust the trim length using a hidden max.name.length argument. See example below:

    plotLoadings(nutrimouse.sgccda, contrib = "min", 
                          max.name.length =  50) ## custom trim length

You may increase to any large number you wish that produces a reasonable plot without a margin error.

Please let me know if you run into any issues.

Best wishes,

Al

Hello,
I am encountering similar issues with PlotLoadings and I tried increasing the custom trim length but it didn’t seem to solve the problem.
I get the following message when I run : plotLoadings(sgccda.res, comp = 2, contrib = ‘max’, method = “median”, max.name.length = 50)
Error:
plotLoadings encountered margin errors. Ensure feature names are not too long (see ‘name.var’ argument) and the ‘Plots’ pane is cleared and enlargened.

how can I solve this problem?

Thank you so much!

Hi @Yixinz,

Potentially one quick fix is to

  • specify the component and block and plot one plot at a time
  • use X11() (in case this is a RStudio style issue).

Kim-Anh