plot_weights {MOFA2} | R Documentation |
An important step to annotate factors is to visualise the corresponding feature weights.
This function plots all weights for a given latent factor and view, labeling the top ones.
In contrast, the function plot_top_weights
displays only the top features with highest loading.
plot_weights( object, view = 1, factors = 1, nfeatures = 10, color_by = NULL, shape_by = NULL, abs = FALSE, manual = NULL, color_manual = NULL, scale = TRUE, dot_size = 1, text_size = 5, legend = TRUE, return_data = FALSE )
object |
a |
view |
a string with the view name, or an integer with the index of the view. |
factors |
character vector with the factor name(s), or numeric vector with the index of the factor(s). |
nfeatures |
number of top features to label. |
color_by |
specifies groups or values (either discrete or continuous) used to color the dots (features). This can be either:
|
shape_by |
specifies groups or values (only discrete) used to shape the dots (features). This can be either:
|
abs |
logical indicating whether to take the absolute value of the weights. |
manual |
A nested list of character vectors with features to be manually labelled (see the example for details). |
color_manual |
a character vector with colors, one for each element of 'manual' |
scale |
logical indicating whether to scale all weights from -1 to 1 (or from 0 to 1 if abs=TRUE). |
dot_size |
numeric indicating the dot size. |
text_size |
numeric indicating the text size. |
legend |
logical indicating whether to add legend. |
return_data |
logical indicating whether to return the data frame to plot instead of plotting |
A ggplot
object or a data.frame
if return_data is TRUE
# Using an existing trained model on simulated data file <- system.file("extdata", "model.hdf5", package = "MOFA2") model <- load_model(file) # Plot distribution of weights for Factor 1 and View 1 plot_weights(model, view = 1, factors = 1) # Plot distribution of weights for Factors 1 to 3 and View 1 plot_weights(model, view = 1, factors = 1:3) # Take the absolute value and highlight the top 10 features plot_weights(model, view = 1, factors = 1, nfeatures = 10, abs = TRUE) # Change size of dots and text plot_weights(model, view = 1, factors = 1, text_size = 5, dot_size = 1)