2

Getting "attempt to apply non-function" when view_follow() is used. It is working as expected when view_follow() function is removed. I am adding this to adjust y-axis basis for the value plotted on the axis. I appreciate a help.

Reproducible code is given below:

library(plyr)
library(dplyr)
library(ggplot2)
library(reshape)
library(reshape2)
library(gganimate)

samplelData <-
    rbind(
            cbind.data.frame(
                    year = as.integer(seq(from=2001,to=2020,by=1)),
                    Country = c('A'),
                    value = c(1:20)
            ),
            cbind.data.frame(
                    year = as.integer(seq(from=2001,to=2020,by=1)),
                    Country = c('B'),
                    value = seq(from=10,to=400,by=20)
            ))

ggplot(samplelData,
                   aes(
                           x = Country,
                           y = value,
                           fill = Country,
                           frame = year
                   )) + geom_point(stat = 'identity', position = 'dodge') +
            transition_reveal(year) + view_follow(fixed_x = TRUE) + labs(title = "Year: {round(frame_along, 0)}")

1 Answers1

1

Below code works: solution found @ https://github.com/thomasp85/gganimate/issues/304

ggplot(samplelData,
   aes(
           x = as.numeric(as.factor(Country)),
           y = value,
           fill = Country,
           frame = year
   )) + geom_bar(stat = 'identity', position = 'dodge') + scale_x_continuous(breaks = 1:2, labels = unique(samplelData$Country)) +
    transition_reveal(year) + view_follow(fixed_x = T, fixed_y = F) + labs(title = "Year: {round(frame_along, 0)}")

Thank you