plot_by_subject: Plot trajectories and density plots of position by subject

View source: R/plotting_functions.R

plot_by_subjectR Documentation

Plot trajectories and density plots of position by subject

Description

Plots all trajectories and generates density plots of position by subject from elevation and bird's eye views.

Usage

plot_by_subject(obj_name, col_by_treat = FALSE, ...)

Arguments

obj_name

A viewr object (a tibble or data.frame with attribute pathviewr_steps that includes "viewr") that has been passed through separate_trajectories() or get_full_trajectories().

col_by_treat

If multiple treatments or sessions, color data per treatment or session. Treatments must be levels in a column named treatment.

...

Additional arguments passed to/from other pathviewr functions.

Details

The input viewr object should have passed through separate_trajectories() or get_full_trajectories(). Optionally, treatments should have been added as levels in a column named treatment. Two plots will be produced, one from a "bird's eye view" of width against length and one from an "elevation view" of height against length. All trajectories will be plotted on a per subject basis, along with density plots of width or height depending on the view. col_by_treat = TRUE, data will be plotted by color according to treatment in both the trajectory plots and the density plots.

Value

A "bird's eye view" plot and an "elevation view" plot, made via ggplot2.

Author(s)

Melissa S. Armstrong

See Also

Other plotting functions: plot_viewr_trajectories(), visualize_frame_gap_choice()

Examples

library(pathviewr)
library(ggplot2)
library(magrittr)

if (interactive()) {
  ## Import the example Motive data included in the package
  motive_data <-
    read_motive_csv(system.file("extdata",
                                "pathviewr_motive_example_data.csv",
                                package = 'pathviewr'))

  ## Clean, isolate, and label trajectories
  motive_full <-
    motive_data %>%
    clean_viewr(desired_percent = 50,
                max_frame_gap = "autodetect",
                span = 0.95)

  ## Plot all trajectories by subject
  motive_full %>%
    plot_by_subject()

  ## Add treatment information
  motive_full$treatment <- c(rep("latA", 100), rep("latB", 100),
                             rep("latA", 100), rep("latB", 149))

  ## Plot all trajectories by subject, color by treatment
  motive_full %>%
    plot_by_subject(col_by_treat = TRUE)
}

pathviewr documentation built on March 31, 2023, 5:47 p.m.