Skip to contents

This will plot the maximum value specified by metric across two conditions.

Usage

plot_max_probability(
  df,
  x_axis_condition,
  y_axis_condition,
  metric = "probability",
  xmax = 1,
  ymax = 1,
  x_label = NULL,
  y_label = NULL
)

Arguments

df

Data Frame or Tibble with the following columns:

x_axis_condition

Character, condition value to use on x-axis, e.g. "control".

y_axis_condition

Character, condition value to use on y-axis, e.g. "drug".

metric

Character, P() metric to plot, e.g. density, probability. Defaults to "probability".

xmax

Optional integer, maximum x-value to plot, values are rounded the nearest 1. Default is 1, ymin is fixed at 0.

ymax

Optional integer, maximum y-value to plot, values are rounded the nearest 1. Default is 1, ymin is fixed at 0.

x_label

Optional character, custom label for the x-axis. Default NULL, will use the column name from x_axis_condition.

y_label

Optional character, custom label for the y-axis. Default NULL, will use the column name from y_axis_condition.

Value

ggplot2 object

Note

This function is intended to use with aggregated data in a long format that is extracted from create_histogram_df.

See also

Examples

library(magrittr, include.only = "%>%")

bins <- seq(0.5, 39.5, by = 1)
n_bins <- length(bins)
conditions <- c("control", "drug")
n_conditions <- length(conditions)

# example output from create_histogram_df()
simple_tbl <-
  tibble::tibble(
    cell_id = "cell",
    experiment_id = "example",
    condition = rep(conditions, each = n_bins),
    h_bin_centers = rep(bins, n_conditions),
    probability = 0,
    density = 1
  ) %>%
  dplyr::mutate(probability = dplyr::case_when(
    condition == "control" & h_bin_centers %in% c(1.5, 11.5) ~ 0.75,
    condition == "drug" & h_bin_centers %in% c(1.5, 11.5) ~ 0.5,
    .default = 0
  ))

plot_max_probability(
  simple_tbl,
  x_axis_condition = "control",
  y_axis_condition = "drug",
  metric = "probability",
  xmax = 1,
  ymax = 1
)