Skip to content

Commit

Permalink
add plotCelltypeProportions function
Browse files Browse the repository at this point in the history
  • Loading branch information
rafaeldossantospeixoto committed Aug 22, 2024
1 parent 8a603bd commit 274725f
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions R/visualization.R
Original file line number Diff line number Diff line change
Expand Up @@ -343,6 +343,36 @@ vizShuffledGrids <- function(cells, shuffledList, scale,



#' Plot Cell-type Proportions
#'
#' For a chosen a neighborhood distance, plot a histogram of
#' the proportion of each neighbor cell type inside the neighborhood of the
#' reference cell type for all reference cell types.
#'
#' @param cells sf data.frame; as produced by crawdad::toSF function: cells with
#' cell types annotated in the celltypes column and point positions in the
#' geometry column
#' @param dist numeric; distance used to define the neighborhood
#'
#' @return ggplot2 plot; the a histogram of the proportions
#'
#' @export
plotCelltypeProportions <- function(cells, dist) {

## for each cell type
celltypes <- unique(cells$celltypes)
props <- lapply(celltypes, calculateCelltypeProportions,
cells = cells, dist = dist)
df <- data.frame(proportions = unlist(props))

df %>% ggplot2::ggplot(ggplot2::aes(x = proportions)) +
ggplot2::geom_histogram(color='#006437', fill='white', bins = 100) +
ggplot2::theme_bw()

}



#' Plot trends with ggplot2
#'
#' @description The input data.frame should be the results list from `findTrends()` that has been melted into a data.frame using `meltResultsList()`.
Expand Down

0 comments on commit 274725f

Please sign in to comment.