Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

showSelected splits on 'built' data #145

Open
cpsievert opened this issue Mar 27, 2016 · 2 comments
Open

showSelected splits on 'built' data #145

cpsievert opened this issue Mar 27, 2016 · 2 comments

Comments

@cpsievert
Copy link
Collaborator

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
Copy link
Collaborator Author

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

@tdhock
Copy link
Owner

tdhock commented Mar 30, 2016

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants