animate_movement: Animate motioncapture data in the planes of the movement.

View source: R/animation_functions.R

animate_movementR Documentation

Animate motioncapture data in the planes of the movement.

Description

animate_movement() animates motioncapture data that is projected onto the planes of the movment using mocapr::project_full_body_to_MP(). Each frame contains a view from the side and front of the direction of movement. The definitions of front and side are dictated by a direction going from the position of the subject at first frame to the position of the subject at the last frame of the movement.

Usage

animate_movement(
  .data,
  planes = c("R", "F"),
  planes_in_rows_or_cols = c("cols"),
  row_facets = NULL,
  col_facets = NULL,
  subject = NULL,
  remove_facet_labels = TRUE,
  use_geom_point = TRUE,
  line_colored = TRUE,
  line_colored_size = 1,
  line_colored_alpha = 1,
  line_black = TRUE,
  line_black_size = 1,
  line_black_alpha = 0.5,
  point = TRUE,
  point_size = 1.5,
  circle_size = 40,
  point_alpha = 1,
  head_scale = 2,
  torso_scale = 1.5,
  return_data = FALSE,
  return_plot = FALSE,
  reduce_data = FALSE,
  ...
)

Arguments

.data

A tibble containing joint center positions in the anatomical planes generated using the project_to_MP() function.

planes

Planes to animate. Must be one or both of c("R", "F"). The planes are created by combining the suplied direction with the up-direction. Defaults to c("R", "F").

planes_in_rows_or_cols

Facet the chosen planes in either rows or columns. Must be one of c("rows", "cols"). Defaults to "cols".

row_facets

Make additional row-facets in the animation using a given variable. Defaults to NULL.

col_facets

Make additional column-facets in the animation using a given variable. Defaults to NULL.

subject

Column that contains subject ID. Is only needed if more than one subject is present in the same frame.

remove_facet_labels

Remove the facet labels. Defaults to TRUE.

use_geom_point

Defaults to TRUE. If TRUE, points in the animation will be created using ggplot2::geom_point(). If FALSE, points are created using ggforce::geom_circle(). This will ensure correct size-proportions of the points, and that no points are croped out of the animation. However, it comes at the prize of much longer rendering-times.

line_colored

Shall the joints be connected by colored lines? (TRUE or FALSE). Defaults to TRUE.

line_colored_size

The size of the colored lines connecting the joint centers.

line_colored_alpha

The alpha value of the colored lines connecting the joint centers.

line_black

Shall the joints be connected by black lines? (TRUE or FALSE). Defaults to TRUE.

line_black_size

The size of the black lines connecting the joint centers.

line_black_alpha

The alhpa value of the black lines connecting the joint centers.

point

Shall the joint centers be marked by points? (TRUE or FALSE). Defaults to TRUE.

point_size

The size of the joint centers when use_geom_point = TRUE.

circle_size

The size of the joint centers when use_geom_point = FALSE.

point_alpha

The alpha of the points or circles that mark the joint centers.

head_scale

The size of the head relative to the joint-centers.

torso_scale

The size of the torso line relative to the remaing lines.

return_data

Return the wrangled data before it is sent to ggplot. This is useful for understanding the data-structure and for developmental purposes.

return_plot

Return a plot instead of an animaiton. This is useful for customizing the plot before passing it to gganimate::

reduce_data

Defaults to FALSE. If TRUE the function will reduce the input data to only include the variables that are needed for the plot or animation.This may improve performance slightly.

...

Additional arguments are passed to gganimate::animate.

Value

Defaults to an animated gif. Different outputs can be achieved by passing different arguments via ... to the gganimate::animate() function. If return_plot = TRUE a ggplot plot is returned. If return_data = TRUE a tibble is returned.

Examples

# Prepare data
df <- dplyr::filter(mocapr::mocapr_data, movement_nr == 1)
df <- project_full_body_to_MP(df)
df <- dplyr::filter(df, frame %in% c(1, 50, 100, 150, 200))

# Return wrangled data
mocapr::animate_movement(df, return_data = TRUE)

# Return plot factted on frame
mocapr::animate_movement(df,
  return_plot = TRUE,
  planes_in_rows_or_cols = "rows",
  col_facets = frame
  )

# Same as above, but use ggforce::geom_circle()
mocapr::animate_movement(df,
  return_plot = TRUE,
  use_geom_point = FALSE,
  planes_in_rows_or_cols = "rows",
  col_facets = frame
  )


steenharsted/mocapr documentation built on Feb. 1, 2024, 1:49 p.m.