Skip to content

Commit

Permalink
Added sampleBarGraph function
Browse files Browse the repository at this point in the history
  • Loading branch information
mpmorley committed Oct 14, 2021
1 parent 1dd3888 commit 34802cd
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 1 deletion.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ Maintainer: Who to complain to <[email protected]>
Description: Functions to run Seurat, slingshot, monocle and other scRNA packages on single cell data
License: What license is it under?
LazyData: TRUE
RoxygenNote: 7.1.1
RoxygenNote: 7.1.2
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ export(plotLineangeGene)
export(processExper)
export(runPseudoTimeDGE)
export(runSlingshot)
export(sampleBarGraph)
export(setSDS)
import(ComplexHeatmap)
import(DoubletFinder)
Expand Down
37 changes: 37 additions & 0 deletions R/Plotting.R
Original file line number Diff line number Diff line change
@@ -1,4 +1,41 @@

#'Plot a stacked bar graph of per Sample contribtion
#' @param object Seurat object
#' @param group.by Variable for x axis typicall cluster or celltype
#' @param cols Color palette for grouping variable
#' @export

sampleBarGraph <- function(object,group.by=NULL,col=NULL){
if(is.null(group.by)){
print("group.by cannot be null")
exit()
}
if(is.null(object$sample)){
print("Cannot find Sample field in meta data")
exit()
}


p <- object@meta.data %>%
group_by(sample,!!sym(group.by)) %>%
summarise(n = n()) %>%
mutate(pct = n / sum(n)) %>%
ggplot(.,aes(x=!!sym(group.by),y=pct,fill=sample)) +
geom_bar(position="fill", stat="identity") +
scale_y_continuous(labels = scales::percent_format()) +
scale_fill_manual(values=col) +
theme_bw() + theme(legend.position = 'bottom')

if(!is.null(col)){
p <- p + scale_fill_manual(values=col)
}
p


}



#'Plot Pairwise PCA plots.
#' @param object Seurat object
#' @param dims Compute N PC dims
Expand Down
18 changes: 18 additions & 0 deletions man/sampleBarGraph.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 34802cd

Please sign in to comment.