Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

use metadata (or active ident) in plot_stat #15

Open
williamsdrake opened this issue Aug 26, 2021 · 2 comments
Open

use metadata (or active ident) in plot_stat #15

williamsdrake opened this issue Aug 26, 2021 · 2 comments

Comments

@williamsdrake
Copy link

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:

cluster = dataset[['seurat_clusters']][[1]])

length(unique(dataset[['seurat_clusters']][[1]]))

@williamsdrake
Copy link
Author

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]]))
  }

@iddryg
Copy link

iddryg commented Aug 31, 2021

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants