animint icon indicating copy to clipboard operation
animint copied to clipboard

showSelected splits on 'built' data

Open cpsievert opened this issue 8 years ago • 2 comments

Consider the following example:

d <- data.frame(
  x = c(replicate(5, LETTERS[1:10])),
  y = c(replicate(5, rbinom(10, 50, 0.5))),
  z = rep(1:5, each = 10)
)
plotList <- list(
  plot = ggplot() + geom_bar(
    data = d, aes(x, y, showSelected = z), stat = "identity"
  ),
  time = list(variable = "z", ms = 1000),
  duration = list(z = 1000)
)
animint2dir(plotList)

I find the result a bit surprising. I assume it's because we split (by showSelected) on the 'built' data, but in this case, you'd really want to build/train on each subset of data.

cpsievert avatar Mar 27 '16 22:03 cpsievert

Note, however, that this seems like a significant change that could have significant consequences for performance of the complier

cpsievert avatar Mar 27 '16 22:03 cpsievert

I got this data viz from your code http://bl.ocks.org/tdhock/raw/147f3bd1d465a9536a1b7a0face500cc/

yeah that is definitely surprising but for this simple example you can get the desired result by using position="identity" http://bl.ocks.org/tdhock/raw/e7b2a527699c010aabaf9c5219bdaee4/

plotList <- list(
  plot = ggplot() + geom_bar(
    data = d, aes(x, y, showSelected = z), stat = "identity", position="identity"
  ),
  time = list(variable = "z", ms = 1000),
  duration = list(z = 1000)
)

Below is a more complicated example for which there is no workaround

df <- data.frame(
  letter = c(replicate(4, LETTERS[1:5])),
  count = c(replicate(4, rbinom(5, 50, 0.5))),
  stack = rep(rep(1:2, each = 5), 2),
  facet = rep(1:2, each = 10)
  )
gg <- ggplot() + geom_bar(
  aes(letter, count, fill = stack, showSelected=facet),
  data = df,
  stat = "identity",
  position="stack"
  )
gg+facet_grid(facet ~ .)
complicated <- list(
  plot = gg,
  time = list(variable = "facet", ms = 1000),
  duration = list(facet = 1000)
  )
animint2dir(complicated)

with position=stack http://bl.ocks.org/tdhock/raw/36cdacc1dbe5d5de894e2d05be92e327/

with position=identity http://bl.ocks.org/tdhock/raw/20d7879f055bd4670e8d3eb4a38e4e7a/

desired result is bar-position-bug

Rather than re-writing the compiler to compute "built" data for each showSelected subset, I think a better solution would be to re-code all the stats and position computations in the renderer. Then animint could support more kinds of interactive graphics, e.g. https://github.com/tdhock/animint/blob/master/inst/examples/stats.R

tdhock avatar Mar 30 '16 18:03 tdhock