I am trying to use gganimate package of R, to create an animation of a bunch of histograms, where each frame of the animation shows a histogram of an image. I have ~400 images, so ~400 columns. My data looks like this:
| bins.left | bins.right | hist1 | hist 2 | ... | hist n |
and as you see, I need each column be considered as the Y value of the histogram, in each frame. In other words, my animation should iterate over the columns.
But all the examples that I have studied on the Internet, seem to be considering only one column as the identifier of the frames. For instance in this example:
mapping <- aes(x = gdpPercap, y = lifeExp,
size = pop, color = continent,
frame = year)
p <- ggplot(gapminder, mapping = mapping) +
geom_point() +
scale_x_log10()
the attribute 'Year' is considered as the iterator. This data looks like this:
country continent year lifeExp pop gdpPercap
<fctr> <fctr> <int> <dbl> <int> <dbl>
1 Afghanistan Asia 1952 28.801 8425333 779.4453
2 Afghanistan Asia 1957 30.332 9240934 820.8530
3 Afghanistan Asia 1962 31.997 10267083 853.1007
4 Afghanistan Asia 1967 34.020 11537966 836.1971
5 Afghanistan Asia 1972 36.088 13079460 739.9811
6 Afghanistan Asia 1977 38.438 14880372 786.1134
The reason that I don't want to modify my data to fit into such a pattern is that if I keep all the histograms in one column, my data frame will be extremely lengthy (length = ~ 16000 * 400) and difficult to handle. In addition, it is not intuitive to keep my data in such a confusing fashion. I believe there must be an easy solution to my problem. Any suggestion is highly appreciated.