Creates a custom feature plot for visualizing a feature's values on a reduced dimension embedding (e.g., UMAP or t-SNE).
CustomFeaturePlot(
coord,
value,
reduction = NULL,
dims = 1:2,
value_name = NULL,
title_name = NULL,
order_point = TRUE
)
A Seurat object or a matrix of coordinates. If a Seurat object is provided, embeddings will be extracted from Seurat.
A vector of values to plot. If coord
is a Seurat object, value
can be a column name from coord@meta.data
.
Character; the name of the reduction embedding to use (e.g., "umap", "tsne"). Default is NULL.
A vector specifying which dimensions to use. Default is c(1,2).
Character; the name of the value to be used in the plot legend. Default is NULL.
Character; the title of the plot. Default is NULL.
Logical; whether to order points by value. Default is TRUE.
A ggplot2 object representing the custom feature plot.
# Example with Seurat object
library(Seurat)
#> Attaching SeuratObject
seurat_obj <- CreateSeuratObject(matrix(runif(2000), nrow = 200))
#> Error in CreateAssayObject(counts = counts, min.cells = min.cells, min.features = min.features, row.names = row.names): No cell names (colnames) names present in the input matrix
seurat_obj <- RunUMAP(seurat_obj, dims = 1:10)
#> Error in RunUMAP(seurat_obj, dims = 1:10): object 'seurat_obj' not found
seurat_obj$feature <- rnorm(200)
#> Error in seurat_obj$feature <- rnorm(200): object 'seurat_obj' not found
plot <- CustomFeaturePlot(seurat_obj, "feature", reduction = "umap", title_name = "Feature Plot")
#> Error in CustomFeaturePlot(seurat_obj, "feature", reduction = "umap", title_name = "Feature Plot"): object 'seurat_obj' not found
print(plot)
#> function (x, y, ...)
#> UseMethod("plot")
#> <bytecode: 0x560b60892860>
#> <environment: namespace:base>
# Example with coordinate matrix
coord <- matrix(rnorm(200), nrow = 100, ncol = 2)
value <- rnorm(100)
plot <- CustomFeaturePlot(coord, value, title_name = "Custom Plot")
#> Warning: the condition has length > 1 and only the first element will be used
#> Error in as.name(colnames(coord)[1]): invalid type/length (symbol/0) in vector allocation
print(plot)
#> function (x, y, ...)
#> UseMethod("plot")
#> <bytecode: 0x560b60892860>
#> <environment: namespace:base>