The inspiration for this package comes from the NY Times animated plot. The challenge of reproducing the animation is the amount of code required. This package tries to solve that by reducing it to only three steps. This package also adds a new element of proportional shaded area.
In this stage, we first need to transform the data into the categorized format. This function will calculate the scaling based on the argument the user provided.
The data needs to contain the following variable for the function to work:
dbl_change
, A data frame that contained the
numerical values.id
, needs to be a factor variable.values
, needs to be a numeric variable.time
, needs to be an integer variable.There are also additional options that allow the user to customize.
The function can calculate four different scales using these options.
# rank scaling
rank_scaling <- anim_prep(data = dbl_change,
id = id,
values = values,
time = time)
# absolute scaling
absolute_scaling <- anim_prep(data = dbl_change,
id = id,
values = values,
time = time,
scaling = "absolute")
# rank scaling by group
rank_group_scaling <- anim_prep(data = dbl_change,
id = id,
values = values,
time = time,
group_scaling = gp)
# absolute scaling by group
absolute_group_scaling <- anim_prep(data = dbl_change,
id = id,
values = values,
time = time,
group_scaling = gp,
scaling = "absolute")
rank_scaling
#> # A tibble: 400 × 4
#> id time qtile label
#> <fct> <int> <int> <chr>
#> 1 1 2020 3 3
#> 2 2 2020 2 2
#> 3 3 2020 4 4
#> 4 4 2020 3 3
#> 5 5 2020 2 2
#> 6 6 2020 2 2
#> 7 7 2020 4 4
#> 8 8 2020 4 4
#> 9 9 2020 3 3
#> 10 10 2020 4 4
#> # ℹ 390 more rows
This function will return a categorized
data.
After preparing the data, we can now plot it. There are three plots available in this package:
kangaroo
, which plots the observation’s movement over
time.wallaby
, which subset the plot to either
top
or bottom
and see which group they are in
after the observational period.funnel_web_spider
, which is a faceted plot by time
variable.dbl_categorized <- anim_prep(data = dbl_change,
id = id,
values = values,
time = time,
group = gp)
# kangaroo plot
kangaroo_plot(dbl_categorized)
#> You can now use the animbook::anim_animate() function to
#> transform it into an animated object
# wallaby plot
wallaby_plot(dbl_categorized)
#> You can now use the animbook::anim_animate() function to
#> transform it into an animated object
The kangaroo
and wallaby
plots can be
animated using the function of the next stage.
funnel_web_spider
only supported static plot. We can also
choose whether we want to animate the plot using gganimate or
plotly.
To animate the plot, we need to save the plot into an object, which then can be passed on to the function.