transformr (version 0.1.1)

tween_sf: Transition between data.frames containing sfc columns

Description

This function is equivalent to tweenr::tween_state() except that it understands sf::sfc columns, as defined by the sf package. An sfc column is a column containing simple features and can this hold both points, lines polygons and more. tween_sf currently has support for (multi)point, (multi)linestring, and (multi)polygon types and requires that the transition is between compatible types (points-to-points, linestring-to-linestring, polygon-to-polygon). For (multi)linestring and (multi)polygon, the behavior is similar to tween_path() and tween_polygon() respectively, with each feature beeing run through the respective function with match = FALSE. For (multi)points it behaves more or less like tweenr::tween_state() except additional points are added as needed to make the to stages contain the same number of points. Points are added on top of existing points so it appears as if the points are divided into more.

Usage

tween_sf(.data, to, ease, nframes, id = NULL, enter = NULL,
  exit = NULL)

Arguments

.data

A data.frame to start from. If .data is the result of a prior tween, only the last frame will be used for the tween. The new tween will then be added to the prior tween

to

A data.frame to end at. It must contain the same columns as .data (exluding .frame)

ease

The easing function to use. Either a single string or one for each column in the data set.

nframes

The number of frames to calculate for the tween

id

The column to match observations on. If NULL observations will be matched by position. See the Match, Enter, and Exit section for more information.

enter

functions that calculate a start state for new observations that appear in to or an end state for observations that are not present in to. If NULL the new/old observations will not be part of the tween. The function gets a data.frame with either the start state of the exiting observations, or the end state of the entering observations and must return a modified version of that data.frame. See the Match, Enter, and Exit section for more information.

exit

functions that calculate a start state for new observations that appear in to or an end state for observations that are not present in to. If NULL the new/old observations will not be part of the tween. The function gets a data.frame with either the start state of the exiting observations, or the end state of the entering observations and must return a modified version of that data.frame. See the Match, Enter, and Exit section for more information.

Value

A data.frame containing intermediary states

Examples

Run this code
# NOT RUN {
library(magrittr)
star_hole <- poly_star_hole(st = TRUE)
circles <- poly_circles(st = TRUE)
spiral <- path_spiral(st = TRUE)
waves <- path_waves(st = TRUE)
random <- point_random(st = TRUE)
grid <- point_grid(st = TRUE)
df1 <- data.frame(geo = sf::st_sfc(star_hole, spiral, random))
df2 <- data.frame(geo = sf::st_sfc(circles, waves, grid))

tween_sf(df1, df2, 'linear', 30)

# }

Run the code above in your browser using DataLab