R/fplot.R

#' Density plotting for markers
#'
#' This function takes object from DiffSOM::Load as input,
#'   and takes marker as an optional argument to plot the
#'   density plot for markers.
#'
#' @section Warning:
#' Some markers might be missing in the plot, but this problem
#' isn't yet debugged.
#'
#' @param input An object from DiffSOM::Load.
#' @param marker All markers(default); marker(s) name.
#' @return Density plot(s) for the defined markers.
#' @import tibble ggplot2 magrittr dplyr tidyr ggridges DiffSOM
#' @export fplot


fplot <- function(input, marker="all"){
  if(marker == "all"){
    marker <- input$fs$prettyColnames %>%
      enframe() %>%
      select(value) %>%
      separate(col="value", into = c("value","rubbish"), sep = ' ') %>%
      select(value) %>%
      filter(!grepl("time|residual|offset|event*|center|file*", value, ignore.case = TRUE))

      col_list <- int_ExportData(input) %>% colnames() %>% as_tibble()
      marker <- inner_join(marker, col_list, by = "value") %>%
        .$value %>%
        as.character()
  }

  p <- int_ExportData(input) %>%
    select(marker) %>%
    gather(key = "marker") %>%
    ggplot(aes(x=value, fill = marker, y = marker))
  p + geom_density_ridges(aes(height =..ndensity..), scale = 1.2) +
    scale_x_continuous(limits = c(-3.5, 5)) +
    ggtitle('Histogram of Marker Expression')
}
AbhivKoladiya/CytoDataViz documentation built on June 23, 2019, 3:31 a.m.