mixOmicsTeam/mixOmics

plotLoadings margin problem

aljabadi opened this issue · 0 comments

problem

Trying to do a plotLoading of a diablo object, where the feature names are too long we get an Error:

suppressMessages(library(mixOmics))

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 = "max")
#> Error in plot.new(): figure margins too large

cause

traceback shows:

traceback()
5: plot.new()
4: barplot.default(df$importance, horiz = TRUE, las = 1, col = df$color, 
       axisnames = TRUE, names.arg = colnames.X, cex.names = size.name, 
       cex.axis = 0.7, beside = TRUE, border = border, xlim = xlim[i, 
           ])
3: barplot(df$importance, horiz = TRUE, las = 1, col = df$color, 
       axisnames = TRUE, names.arg = colnames.X, cex.names = size.name, 
       cex.axis = 0.7, beside = TRUE, border = border, xlim = xlim[i, 
           ]) at plotLoadings.splsda.R#166
2: plotLoadings.sgccda(nutrimouse.sgccda, contrib = "max") at plotLoadings.R#28
1: plotLoadings(nutrimouse.sgccda, contrib = "max")

Even though internally we try to accommodate for length of variables in plot layout, but currently there's no limit in size of the variables which can be long in some datasets. The error is also not informative at its current form.

remedy

A possible solution is to trim long variable names only in plots with a message. As a least-impact remedy, we can simply change the colnames.X passed to barplot functions in various functions, but it should be done before the layout considers their length in the margin specifications.