Compliments create_histogram_df() to generate P() plots over time.
Usage
plot_probability(
df,
plot_stim_times,
plot_value = "probability",
xmax = 40,
ymax = 1,
y_label = NULL,
df_inset = NULL,
sd_value = NULL,
manual_condition_color = NULL,
...
)Arguments
- df
Data Frame or Tibble with the following columns:
h_bin_centers
P() metric from
create_histogram_df(), e.g. density, probability.
- plot_stim_times
Integer, stimulus times in milliseconds.
- plot_value
Character,
dfcolumn to use for plotting. Defaults to "probability".- xmax
Optional integer, maximum x-value to plot in milliseconds (ms), values are rounded to the nearest 10. Default is
40, xmin is fixed at0.- ymax
Optional integer, maximum y-value to plot, values are rounded the nearest 1. Default is
1, ymin is fixed at0.- y_label
Optional character, custom label for the main y-axis. Default
NULL, will use the column name fromplot_value.- df_inset
Optional Data Frame, if present a inset is added to the plot in the upper right corner. Default is
NULL.- sd_value
Character,
dfcolumn to use for plotting error bars. Default isNULL.- manual_condition_color
Character, vector of color values. Default is
NULL, which will automatically generating color values.- ...
Optional vargs, to apply additional ggplot function calls, e.g.
ylim(),ylab(). Ifdf_insetisNULL, see note below.
Note
When adding an inset to the plot, if you want to add additional ggplot function calls, you
must add these using the varg, .... As this function will return a grob
object. However, if the df_inset arg is left at the default value of NULL,
then a ggplot object is returned and additional ggplot function calls can added post hoc, e.g.
plot_probability() + ylab("y-axis label").
Examples
library(magrittr, include.only = "%>%")
# example setup
bins <- seq(0.5, 39.5, by = 1)
n_bins <- length(bins)
conditions <- c("control", "drug_1")
n_conditions <- length(conditions)
# example output from create_histogram_df()
simple_tbl <-
tibble::tibble(
condition = rep(conditions, each = n_bins),
h_bin_centers = rep(bins, n_conditions),
probability = 0
) %>%
dplyr::mutate(probability = dplyr::case_when(
condition == "control" & h_bin_centers %in% c(1.5, 11.5) ~ 1,
condition == "drug_1" & h_bin_centers %in% c(1.5, 11.5) ~ 0.5,
.default = 0
))
plot_probability(
df = simple_tbl,
plot_stim_times = c(0, 10, 20),
plot_value = "probability"
)