| olink_umap_plot | R Documentation |
Computes a manifold approximation and projection using umap::umap and plots the two specified components. Unique sample names are required and imputation by the median is done for assays with missingness <10\ projects and <5\
olink_umap_plot(
df,
color_g = "QC_Warning",
x_val = 1L,
y_val = 2L,
check_log = NULL,
config = NULL,
label_samples = FALSE,
drop_assays = FALSE,
drop_samples = FALSE,
byPanel = FALSE,
outlierDefX = NA,
outlierDefY = NA,
outlierLines = FALSE,
label_outliers = TRUE,
quiet = FALSE,
verbose = TRUE,
...
)
df |
data frame in long format with Sample Id, NPX and column of choice for colors. |
color_g |
Character value indicating which column to use for colors (default QC_Warning). Continuous color scale for Olink(R) Sample Index (OSI) columns OSITimeToCentrifugation, OSIPreparationTemperature and OSISummary is also supported. |
x_val |
Integer indicating which UMAP component to plot along the x-axis (default 1) |
y_val |
Integer indicating which UMAP component to plot along the y-axis (default 2) |
check_log |
A named list returned by |
config |
object of class umap.config, specifying the parameters for the UMAP algorithm (default umap::umap.defaults) |
label_samples |
Logical. If TRUE, points are replaced with SampleID (default FALSE) |
drop_assays |
Logical. All assays with any missing values will be dropped. Takes precedence over sample drop. |
drop_samples |
Logical. All samples with any missing values will be dropped. |
byPanel |
Perform the UMAP per panel (default FALSE) |
outlierDefX |
The number standard deviations along the UMAP dimension plotted on the x-axis that defines an outlier. See also 'Details" |
outlierDefY |
The number standard deviations along the UMAP dimension plotted on the y-axis that defines an outlier. See also 'Details" |
outlierLines |
Draw dashed lines at +/- outlierDefX and outlierDefY standard deviations from the mean of the plotted PCs (default FALSE) |
label_outliers |
Use ggrepel to label samples lying outside the limits set by the outlierLines (default TRUE) |
quiet |
Logical. If TRUE, the resulting plot is not printed |
verbose |
Logical. Whether warnings about the number of samples and/or assays dropped or imputed should be printed to the console. |
... |
coloroption passed to specify color order. |
The plot is printed, and a list of ggplot objects is returned.
If byPanel = TRUE, the data processing (imputation of missing values etc) and subsequent UMAP is performed separately per panel. A faceted plot is printed, while the individual ggplot objects are returned. The arguments outlierDefX and outlierDefY can be used to identify outliers in the UMAP results. Samples more than +/- outlierDefX and outlierDefY standard deviations from the mean of the plotted UMAP component will be labelled. Both arguments have to be specified.
NOTE: UMAP is a non-linear data transformation that might not accurately preserve the properties of the data. Distances in the UMAP plane should therefore be interpreted with caution.
A list of objects of class "ggplot", each plot contains scatter plot of UMAPs
if (rlang::is_installed(pkg = c("umap", "ggrepel", "ggpubr"))) {
npx_data <- npx_data1 |>
dplyr::mutate(
SampleID = paste(.data[["SampleID"]], "_", .data[["Index"]], sep = "")
)
check_log <- check_npx(df = npx_data)
# UMAP using all the data
OlinkAnalyze::olink_umap_plot(
df = npx_data,
color_g = "QC_Warning",
check_log = check_log
)
# UMAP per panel
g <- OlinkAnalyze::olink_umap_plot(
df = npx_data,
color_g = "QC_Warning",
byPanel = TRUE,
check_log = check_log
)
# Plot only the Inflammation panel
g$Inflammation
# Label outliers
OlinkAnalyze::olink_umap_plot(
df = npx_data,
color_g = "QC_Warning",
outlierDefX = 2L,
outlierDefY = 4L,
check_log = check_log
)
OlinkAnalyze::olink_umap_plot(
df = npx_data,
color_g = "QC_Warning",
outlierDefX = 3L,
outlierDefY = 2L,
byPanel = TRUE,
check_log = check_log
)
# Retrieve outliers
p <- OlinkAnalyze::olink_umap_plot(
df = npx_data,
color_g = "QC_Warning",
outlierDefX = 3L,
outlierDefY = 2L,
byPanel = TRUE,
check_log = check_log
)
outliers <- lapply(p, function(x) x$data) |>
dplyr::bind_rows() |>
dplyr::filter(
.data[["Outlier"]] == 1L
)
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.