Scillus icon indicating copy to clipboard operation
Scillus copied to clipboard

use metadata (or active ident) in plot_stat

Open williamsdrake opened this issue 4 years ago • 2 comments

Thanks for your useful project. When using plot_stat, I've noticed that the stacked barplot is fixed to the 'seurat_clusters' in the metadata. Would it be possible for an additional argument to be added so that we can use other metadata to label the stacked barplot?

Referring to these lines: https://github.com/xmc811/Scillus/blob/4e7884d29ba8997669ff848983257cb0cf37a318/R/visualization.R#L392 https://github.com/xmc811/Scillus/blob/4e7884d29ba8997669ff848983257cb0cf37a318/R/visualization.R#L400

williamsdrake avatar Aug 26 '21 21:08 williamsdrake

Got impatient so I modified the relevant code adding a 'clusterLabel' argument which defaults to "seurat_clusters". Would be nice if you added it to the project. Here it is:

plot_stat <- function(dataset, 
                      plot_type, 
                      clusterLabel = "seurat_clusters",
                      group_by = "sample",
                      pal_setup = 'Set2',
                      plot_ratio = 1,
                      text_size = 10,
                      tilt_text = FALSE) {
  
  if (is.data.frame(pal_setup)) {
    pal <- pal_setup[pal_setup[[1]] == group_by,][[2]]
  } else {
    pal <- pal_setup
  }
  
  stat <- tibble::tibble(group = dataset[[group_by]][[1]], 
                         cluster = dataset[[clusterLabel]][[1]])
  stat %<>%
    group_by(.data$group, 
             .data$cluster) %>%
    summarise(n = n()) %>%
    mutate(freq = n / sum(n))
  
  ncolors <- if (plot_type == 'prop_fill') {
    length(unique(dataset[[clusterLabel]][[1]]))
  } else {
    length(unique(dataset[[group_by]][[1]]))
  }

williamsdrake avatar Aug 30 '21 14:08 williamsdrake

Agreed, I came here to mention this. I'd previously labeled my clusters with the RenameIdents() function in Seurat, and using Scillus am unable to get it to plot with those renamed idents. It only plots the cluster numbers.

I got around this by just writing my Idents to the 'seurat_clusters' metadata column, but a more customizable way like suggested above would be nice.

iddryg avatar Aug 31 '21 19:08 iddryg