Plot results of a principal component analysis
plot_pca(
obj,
PC_x = 1,
PC_y = 2,
n_feats = 500,
scale_feats = FALSE,
na_frac = 0.3,
metadata = NULL,
color_by = NULL,
shape_by = NULL,
point_alpha = 0.7,
point_rel_size = 2,
show_plot = TRUE,
rasterise = FALSE,
...
)
The function displays the plot and returns invisible a list of the plot, the data.frame to make the plot, the vector of percentages of variance explained and the loadings matrix.
A (features x samples) matrix or SummarizedExperiment object
The PC to show on the x-axis.
The PC to show on the y-axis.
Number of top-variable features to include.
Whether to scale the features.
Only consider features with the stated maximum fraction of NAs or NaNs. NA/NaNs will be mean-imputed for PCA.
A data.frame used for annotating samples. rownames(metadata)
must match colnames(obj)
.
Variable by which to color points. Must be a column in metadata or in colData(obj)
.
Alternatively, it can be the name of a feature (a rowname of obj) or a gene name (an element of rowData(obj)$gene_name).
Variable by which to color points. Must be a column in metadata or in colData(obj)
.
alpha value of geom_point()
relative size of geom_point()
Whether to show the plot or not
Whether to rasterise the point, using ggrastr.
Other parameters passed on to ggrastr::rasterise
If the metadata
or colData
of obj
contain a column colname
, this colum will be removed in the $pca_data
slot,
because this column contains the colnames of the data matrix. Similarly, for the $loadings
slot, the column rowname
is
reserved for the rownames of the data matrix.
set.seed(1)
data <- matrix(rnorm(100*6), ncol=6)
data <- t(t(data)+c(-1, -1.1, -1.2, 1, 1.1, 1.2))
plot_pca(data)
Run the code above in your browser using DataLab