Skip to content

Fix for #409 in transition_reveal() causes some rows to be dropped when there are multiple groups in a panel #480

Closed

Description

@linzi-sg

Situation

After fixing #409 in 1.0.8, TransitionReveal$expand_panel returns

all_frames[!(c(diff(all_frames$.time), 1) <= .Machine$double.eps & all_frames$.phase == 'raw'), ]

instead of

all_frames

Problem

When there are, for example, 2 groups in a dataset, the latter will include 2 rows with .phase = "raw" and .time == max(.time), while the former will only include 1. Consequently, the last frame of the animated plot will only show the geom(s) for one group, instead of both.

A problem of this nature was recently described on Stack Overflow. Based on my attempts to reproduce the issue, the above change appears to be responsible.

Proposed workaround

Modifying the code to drop rows by group (instead of by panel) appears to resolve the issue. I tried changing last few rows from:

all_frames$group <- paste0(all_frames$group, '<', all_frames$.frame, '>')
all_frames$.frame <- NULL
all_frames[!(c(diff(all_frames$.time), 1) <= .Machine$double.eps & all_frames$.phase == 'raw'), ]

to:

all_frames <- do.call("rbind", 
                      lapply(split(all_frames, all_frames$group), 
                             function(d) d[!(c(diff(d$.time), 1) <= .Machine$double.eps & d$.phase == "raw"), ]))

all_frames$group <- paste0(all_frames$group, "<", all_frames$.frame, ">")
all_frames$.frame <- NULL
all_frames

p.s. my original suggestion on SO corresponding to #409 was

all_frames %>%
  filter(!(.phase == "transition" & 
               abs(x - lag(x)) <= sqrt(.Machine$double.eps) &
               abs(y - lag(y)) <= sqrt(.Machine$double.eps)))

Which also seems to work fine, at least for this case.

Activity

  1. linzi-sg commented on Apr 1, 2023

    @linzi-sg
    Author

    I also looked at #473. Both suggestions above worked for the example provided by @ddeannd, but only the 2nd version worked for the ampersand example provided by @yutannihilation. (I couldn't get the Japanese font to work properly, so I skipped his first example...)

  2. added a commit that references this issue on Feb 15, 2025
    9e44de6
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions