|
3 | 3 | #' @description Plot the statistics of the cells. |
4 | 4 | #' |
5 | 5 | #' @param object A Seurat object |
6 | | -#' @param ident The column with the cell identities. i.e. clusters. Default: seurat_clusters |
| 6 | +#' @param ident The column with the cell identities. i.e. clusters. Default: NULL |
| 7 | +#' If NULL, the active identity of the Seurat object and the name "Identity" will be used. |
7 | 8 | #' For 'pies', this will be used as the `pie_group_by`. |
8 | 9 | #' For 'heatmap' plot, this will be used as the rows of the heatmap. |
9 | 10 | #' @param group_by The column name in the meta data to group the cells. Default: NULL |
|
66 | 67 | #' |
67 | 68 | #' @return A ggplot object or a list if `combine` is FALSE |
68 | 69 | #' @importFrom rlang sym syms |
| 70 | +#' @importFrom SeuratObject Idents |
69 | 71 | #' @importFrom dplyr %>% summarise mutate ungroup n |
70 | 72 | #' @importFrom tidyr drop_na pivot_wider pivot_longer |
71 | 73 | #' @importFrom plotthis BarPlot CircosPlot PieChart RingPlot TrendPlot AreaPlot SankeyPlot Heatmap RadarPlot SpiderPlot ViolinPlot BoxPlot |
|
152 | 154 | #' x_text_angle = 60, comparisons = TRUE, aspect.ratio = 0.8) |
153 | 155 | #' } |
154 | 156 | CellStatPlot <- function( |
155 | | - object, ident = "seurat_clusters", group_by = NULL, group_by_sep = "_", |
| 157 | + object, ident = NULL, group_by = NULL, group_by_sep = "_", |
156 | 158 | split_by = NULL, split_by_sep = "_", facet_by = NULL, rows = NULL, columns_split_by = NULL, |
157 | 159 | frac = c("none", "group", "ident", "cluster", "all"), rows_name = NULL, name = NULL, |
158 | 160 | plot_type = c("bar", "circos", "pie", "pies", "ring", "donut", "trend", "area", "sankey", "alluvial", "heatmap", "radar", "spider", "violin", "box"), |
159 | 161 | swap = FALSE, ylab = NULL, ... |
160 | 162 | ) { |
161 | 163 | data <- object@meta.data |
| 164 | + if (is.null(ident)) { |
| 165 | + ident <- "Identity" |
| 166 | + data[[ident]] <- Idents(object) |
| 167 | + } |
162 | 168 |
|
163 | 169 | plot_type <- match.arg(plot_type) |
164 | 170 | if (plot_type == "donut") plot_type <- "ring" |
|
0 commit comments