animint2 provides an animated, interactive grammar of graphics
devtools::install_github("tdhock/animint2")For animint2 usage examples, see our extensive set of test cases.
Another good reference is the Animint Designer Manual, which uses the old syntax. We eventually plan to port all of those examples to the new syntax.
This package is a redesign of animint with a cleaner syntax. In the old animint we had showSelected/clickSelects as aesthetics, and in animint2 they are now parameters.
This package contains all forked functions with a_* prefix. For eg: a_geom_point()
Consider the following example data viz, adapted from tests/testthat/test-renderer1-variable-value.R. The data set used to draw the blue line segments in the bottom plot looks like this:
> with(peak.problems, data.frame(selector.name=paste0(problem.name, "peaks"), problem.name, peaks, bases.per.problem))
selector.name problem.name peaks bases.per.problem
1 size.100.problem.1peaks size.100.problem.1 1 100
2 size.100.problem.2peaks size.100.problem.2 1 100
3 size.50.problem.1peaks size.50.problem.1 1 50
4 size.50.problem.2peaks size.50.problem.2 1 50
5 size.50.problem.3peaks size.50.problem.3 1 50
6 size.50.problem.4peaks size.50.problem.4 1 50
7 size.100.problem.1peaks size.100.problem.1 2 100
8 size.100.problem.2peaks size.100.problem.2 2 100
9 size.50.problem.1peaks size.50.problem.1 2 50
10 size.50.problem.2peaks size.50.problem.2 2 50
11 size.50.problem.3peaks size.50.problem.3 2 50
12 size.50.problem.4peaks size.50.problem.4 2 50
> and the old animint code looks like this:
geom_segment(aes(showSelected.variable=selector.name,
showSelected.value=peaks,
clickSelects=problem.name,
showSelected2=bases.per.problem),
data=peaks.dt)- In both animint and animint2, there are “selectors” which are variables in the interactive graphic that can change based on what you click on.
- The
aes(clickSelects)means that whenever you click on one of these segments, theproblem.nameselector will change. For example clicking the segment that is plotted for the first row of data will changeproblem.nametosize.100.problem.1. - The
aes(showSelected2)means that the only segments that will be shown are the ones which correspond to the current value of thebases.per.problemselector. For example the segment for the first row of data will only be shown if100is selected for thebases.per.problemselector. - The
showSelected.variableandshowSelected.valuemean to show the segment only if the value ofshowSelected.valueis the current selection of theshowSelected.valueselector. For example the segment for the first row of data will only be shown if1is selected for thesize.100.problem.1peaksselector.
The new syntax uses parameters instead of a_aes, so is much more concise:
a_geom_segment(showSelected=c(selector.name="peaks", "bases.per.problem"),
clickSelects="problem.name")Both showSelected and clickSelects should be character
vectors. Named elements of the character vector are interpreted as the
old variable/value aes, and un-named elements are interpreted as the
old clickSelects/showSelected aes.