Manually change plotIndiv label

Hello mixOmics team

I have tried a sPLS-DA in my analysis and when doing plotInd area prediction background I struggled to manually change legend labels. For example, in ggplot2 I can set scale_fill_manual and change color and labels. Is there a workaround to get it done?

You can adjust the legend title and labels using the scale_colour_discrete() function from ggplot. Note, depending on your scenario, you may need to use the scale_fill_discrete()

library(mixOmics)

data("breast.TCGA")
X <- breast.TCGA$data.train$mirna
Y <- breast.TCGA$data.train$subtype

model <- splsda(X, Y)

bg <- background.predict(model, comp.predicted = 2)

fig <- plotIndiv(model, background = bg, legend=T)$graph


fig <- fig + scale_colour_discrete(name = "Class", labels=c('label1', 'label2', 'label3'))
#> Scale for 'colour' is already present. Adding another scale for 'colour',
#> which will replace the existing scale.
fig

Created on 2022-11-07 with reprex v2.0.2

Thank you Max. It worked for me.

Hello Max,

I try to custom the legend title for plotVar() according to this method, but doesn’t work. Do you know the possible reason?
Like: Fig ← plotVar(final.spls.IHSS, cex = c(3,3), var.names = c(F, F), title = “PLS Correlations - cutoff of 0.5”,
cutoff = 0.7, legend = TRUE, legend.title = “Data”, style = “ggplot2”)$graph
return a NULL value. and if I add + scale_colour_discrete() directly. I got

I also have a question for plotIndiv() I found:
plotIndiv(final.spls.IHSS, ind.names = T,
point.lwd = 2,
rep.space = “XY-variate”, # plot in averaged subspace
group = df_meta$Sources, # colour by time group
pch = as.factor(df_meta$Sample Types), # select symbol
#col.per.group = color.mixo(1:4), # by dose group
legend = TRUE, legend.title = ‘Sources’, legend.title.pch = ‘Sample Type’)

I can not show individual name.

Looking forward to your comments!

Hi @xin

Max has now let the team. We might be able to pick up your request in a couple of months if that is still an issue for plotVar, but this should be a new post as this post is related to plotIndiv.

For plotIndiv, I think the issue is that you cannot have both a symbol and a name. You can consider extracting the $variates and customise the plot yourself.

Kim-Anh

Hi Kim-Anh,

Thanks for your reply! I will try to extract the variates and plot them by myself. And thanks for providing this method and forum for discussion!

1 Like