tween_sf {transformr} | R Documentation |
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 |
to |
A data.frame to end at. It must contain the same columns as .data
(exluding |
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 |
enter , exit |
functions that calculate a start state for new observations
that appear in |
Value
A data.frame containing intermediary states
Examples
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)