R/plotting.R

Defines functions plot_bin plot_loess_segments plot_merged_segments ratio_plot pretty_ratio_plot

Documented in plot_bin plot_loess_segments plot_merged_segments pretty_ratio_plot ratio_plot

#' Plot Bin Reads
#'
#' @param dat
#'
#' @return
#' @export
#'
#' @examples
plot_bin <- function(dat) {
  bin_plot <-
    ggplot2::ggplot(dat) +
    geom_point(aes(abspos,
                   loess.ratio)) +
    xlab("Genome Absolute Position") +
    ylab("GC corrected bin count") +
    theme_classic()

  print(bin_plot)
}

#' Plot Loess
#'
#' @param dat
#'
#' @return
#' @export
#'
#' @examples
plot_loess_segments <- function(dat) {
  loess_plot <- ggplot2::ggplot(dat) +
    geom_point(aes(abspos,
                   log2(loess.ratio + 1e-3))) +
    geom_line(aes(abspos,
                  log2(seg.mean.loess + 1e-3)), color = "red", size = 1.2) +
    xlab("Genome Absolute Position") +
    ylab("log2 (segment mean)") +
    theme_classic()

  print(loess_plot)

}

#' Plot Merged Segments
#'
#' @param dat
#'
#' @return
#' @export
#'
#' @examples
plot_merged_segments <- function(dat) {
  merged_plot <- ggplot2::ggplot(dat) +
    geom_point(aes(abspos,
                   log2(loess.ratio + 1e-3))) +
    geom_line(aes(abspos,
                  seg.mean.ml), color = "red", size = 1.2) +
    xlab("Genome Absolute Position") +
    ylab("log2 (segment mean)") +
    theme_classic()

  print(merged_plot)
}

#' Plot a Ratio Plot
#'
#' @param df
#' @param cell_id
#'
#' @return
#' @export
#'
#' @examples
ratio_plot <- function(df, cell_id = "MDAMB231C8PLATE1C100_S2020_L006_R1_001") {
  ratio_plot <-
    df %>%
    dplyr::filter(cell == cell_id) %>%
    ggplot2::ggplot() +
    geom_point(aes(abspos,
                   ratios_rat)) +
    geom_line(aes(abspos,
                  seg_mean),
              color = "red",
              size = 1.2) +
    xlab("Genome Absolute Position") +
    ylab("Ratio") +
    ggtitle(paste("Cell: ", cell_id)) +
    theme_classic()

  print(ratio_plot)
}

#' Make a pretty ratio plot
#'
#' @param df
#' @param cell_id
#'
#' @return
#' @export
#'
#' @examples
pretty_ratio_plot <- function(df, cell_ids = c("MDAMB231C8PLATE1C100_S2020_L006_R1_001")){

  ggchr.back <- format_chr_for_plot()

  pretty_ratio_plot <-
    ggplot(df %>% filter(cell %in% cell_ids)) +
    geom_point(aes(abspos,
                   ratios_rat),
               shape = 20,
               size = 1,
               alpha = .7,
               color = "gray50") +
    geom_line(aes(abspos, seg_mean), col = "red",
              size = 1.1) +
    facet_wrap("cell") +
    ggchr.back +
    format_ggaes(ggchr.back) +
    xlab("") +
    ylab("Ratio") +
    ggtitle(paste("Cell: ", cell_ids)) +
    NULL

  print(pretty_ratio_plot)
}
whtns/varbintools documentation built on Dec. 1, 2019, 5:15 a.m.