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
Docs: Getting started example #226
Comments
Example 1: Objective: reveal a single point sequentially: reveal library(reprex)
# Packages + Data
library(ggplot2)
library(gganimate)
library(tibble)
df <- tibble(x = -10:10, y = abs(x))
# Plots
p1 <- ggplot(data = df, aes(x, y)) +
geom_point(size = 5) +
transition_manual(x) +
labs(title = "transition_manual(x)")
p1 <- animate(p1)
#> nframes and fps adjusted to match transition
p2 <- ggplot(data = df, aes(x, y)) +
geom_point(size = 5) +
transition_manual(y) +
labs(title = "transition_manual(y)")
p2 <- animate(p2)
#> nframes and fps adjusted to match transition
combine_gifs(plot1 = p1, plot2 = p2)
#> Loading required package: magick
#> Linking to ImageMagick 6.9.9.39
#> Enabled features: cairo, fontconfig, freetype, lcms, pango, rsvg, webp
#> Disabled features: fftw, ghostscript, x11 Created on 2018-12-11 by the reprex package (v0.2.1) Verdict: Success. |
Following on from the previous examples, below are attempts to reveal points sequentially while keeping them on the graph. Thanks Thomas for showing me how to achieve this objective. Example 2: Objective: reveal all points sequentially: reveal # Packages + Data
library(reprex)
library(ggplot2)
library(gganimate)
library(tibble)
df <- tibble(x = -10:10, y = abs(x))
# Plots
p1 <- ggplot(data = df, aes(x, y, group = seq_along(x))) +
geom_point(size = 5) +
transition_reveal(x) +
labs(title = "transition_reveal(x)")
p1 <- animate(p1)
p2 <- ggplot(data = df, aes(x, y, group = seq_along(x))) +
geom_point(size = 5) +
transition_reveal(y) +
labs(title = "transition_reveal(y)")
p2 <- animate(p2)
combine_gifs(plot1 = p1, plot2 = p2)
#> Loading required package: magick
#> Linking to ImageMagick 6.9.9.39
#> Enabled features: cairo, fontconfig, freetype, lcms, pango, rsvg, webp
#> Disabled features: fftw, ghostscript, x11 anim_save("transition_reveal.gif") Created on 2018-12-11 by the reprex package (v0.2.1) Verdict: Success. |
The default
|
This is only possible for some transitions, e.g. transition_manual... In your case the only reason why it can be done with 21 frames is because there is only one layer and each time point fed into transition_reveal is distributed evenly across the range and no point has the same group aesthetic. I'm not going to create special cases for such things as it is likely to break all the time |
also, sorry for breaking all your code, but breaking changes to transition_reveal has just been merged in, removing the |
Thanks Thomas. Will look into this. I'm only just learning the new api, so I don't mind breaking changes. Is there a way to override I haven't updated to the latest version, so let me do that first. But when I tried to set the
|
The number of frames is not really something the transitions should worry about unless the data provided does not support the number of frames requested. The idea is that an animation specification is dimensionless and only upon requesting a render is anything determined. It is thus the responsibility of the |
I follow up with a few more attempts at making introductory examples. I'll update the code as I make progress. Comments welcome. Example 3: Objective: reveal a single line segment sequentially: show Verdict: Thomas says there is no easy way to do this right now... To be continued. |
Example 4: # Packages + Data
library(reprex)
library(ggplot2)
library(gganimate)
library(tibble)
df <- tibble(x = -10:10, y = abs(x))
# Plots
p1 <- ggplot(data = df, aes(x, y)) +
geom_path(size = 2) +
transition_reveal(x) +
labs(title = "geom_path() with transition_reveal(x)")
p1 <- animate(p1)
p2 <- ggplot(data = df, aes(x, y)) +
geom_path(size = 2) +
transition_reveal(y) +
labs(title = "geom_path() with transition_reveal(y)")
p2 <- animate(p2)
combine_gifs(plot1 = p1, plot2 = p2)
#> Loading required package: magick
#> Linking to ImageMagick 6.9.9.39
#> Enabled features: cairo, fontconfig, freetype, lcms, pango, rsvg, webp
#> Disabled features: fftw, ghostscript, x11 Created on 2018-12-11 by the reprex package (v0.2.1) Verdict: Success. Example 4b: Things that go "wrong" when attempting to animate # Packages + Data
library(reprex)
library(ggplot2)
library(gganimate)
library(tibble)
df <- tibble(x = -10:10, y = abs(x))
# Plots
p1 <- ggplot(data = df, aes(x, y)) +
geom_line(size = 2) +
transition_reveal(x) +
labs(title = "geom_line() with transition_reveal(x)")
p1 <- animate(p1)
p2 <- ggplot(data = df, aes(x, y)) +
geom_line(size = 2) +
transition_reveal(y) +
labs(title = "geom_line() with transition_reveal(y)")
p2 <- animate(p2)
combine_gifs(plot1 = p1, plot2 = p2)
#> Loading required package: magick
#> Linking to ImageMagick 6.9.9.39
#> Enabled features: cairo, fontconfig, freetype, lcms, pango, rsvg, webp
#> Disabled features: fftw, ghostscript, x11 # Verdict: Not recommended. Created on 2018-12-11 by the reprex package (v0.2.1) |
In general, transition_manual should only be used if you want to forego gganimate's automatic handling altogether... using it to reveal a line is not what it does... |
You should generally be hesitant to use geom_line with transition_reveal unless you reveal along the x-axis. using geom_path will give you the expected result |
Thanks for the feedback Thomas. I have updated the examples above. Below an updated summary. Example 1: Objective: reveal a single point sequentially: reveal Example 2: Objective: reveal all points sequentially: reveal Example 3: Objective: reveal a single line segment sequentially: reveal Example 4: Objective: reveal a line sequentially: reveal |
For example 2, a simple modification is all it takes: ggplot(data = df, aes(x, y, group = seq_along(x)) + #group just need to be unique for each point
geom_point(size = 5) +
transition_reveal(x) +
labs(title = "transition_reveal(x)") |
I still don't understand what you wan to achieve in example 3 |
Thanks for your help Thomas. For me, with or without |
library(gganimate)
#> Loading required package: ggplot2
df <- data.frame(x = -10:10, y = abs(-10:10))
ggplot(data = df, aes(x, y, group = seq_along(x))) + #group just need to be unique for each point
geom_point(size = 5) +
transition_reveal(x) Created on 2018-12-11 by the reprex package (v0.2.1) |
stupid me I had the Example 4 with fewer frames than default. The first 5 frames
|
That is basically example 4 with a low framerate |
library(gganimate)
#> Loading required package: ggplot2
df <- data.frame(x = -10:10, y = abs(-10:10))
# Plots
p1 <- ggplot(data = df, aes(x, y)) +
geom_path(size = 2) +
transition_reveal(x) +
labs(title = "geom_path() with transition_reveal(x)")
animate(p1, nframes = 10, fps = 1) Created on 2018-12-11 by the reprex package (v0.2.1) |
Oh I understand now: you set I wrote too fast, I meant this for Example 3:
|
there is currently no way to do that gracefully |
I have updated Examples 1, 2, and 4. Feel free to put them together inside a "Getting Started" wiki, if you think they could be useful. I certainly feel much more comfortable with the package having worked through them and been able to compare different options side by side. I'll close by thanking you for a great package and your kind help! |
Below an animation intended to illustrate the use of counters for Example 5: Printing counters library(reprex)
library(ggplot2)
library(gganimate)
# Data
df <- structure(list(x = 1:50, y = c(1.13220278129597, 1.19052387615662,
1.08245817019419, 1.092026178772, 1.10044827996026, 1.10761637669097,
1.15670117446199, 1.10614650904771, 1.10850359605767, 1.10888736691465,
1.13057762527772, 1.1097108873825, 1.10079690884314, 1.06299876187194,
1.02176309803305, 1.00468521705448, 1.01677335399114, 1.05763641886816,
1.04518028693855, 1.03553964517436, 1.05894958690745, 1.05640164807922,
1.03859260999251, 1.02183113310639, 1.02216937673504, 1.02203574505795,
1.02211730017492, 1.02587886449655, 1.02756514422318, 1.03358427512605,
1.04717537432021, 1.04464239078604, 1.05032082010357, 1.04757090239588,
1.04442488099086, 1.04616044456226, 1.0379115427868, 1.03534523721584,
1.02857437409865, 1.03808867100352, 1.0402482762807, 1.04328589395803,
1.03610034851675, 1.0311223037094, 1.02037361781279, 1.00817879202418,
1.02145919273311, 1.02037759867125, 1.01944090162799, 1.02264408869067
)), row.names = c(NA, 50L), class = "data.frame")
# cumulative = FALSE
n = nrow(df) # number of frames to match sample size
p1 <- ggplot(data = df, aes(x = x, y = y)) +
transition_manual(x) +
geom_point(size = 2, color = "darkblue") +
labs(x = "sample size",
y = "sampling mean",
title = "Number of samples = {frame}, Maximum size = {nframes}")
p1 <- animate(p1, nframes = n, fps = 1)
# cumulative = TRUE
n = nrow(df) # number of frames to match sample size
p2 <- ggplot(data = df, aes(x = x, y = y, group = seq_along(x))) +
transition_reveal(x) +
geom_point(size = 2, color = "darkblue") +
labs(x = "sample size",
y = "sampling mean",
title = "Number of samples = {frame}, Maximum size = {nframes}")
p2 <- animate(p2, nframes = n, fps = 1)
combine_gifs(plot1 = p1, plot2 = p2)
#> Loading required package: magick
#> Linking to ImageMagick 6.9.9.39
#> Enabled features: cairo, fontconfig, freetype, lcms, pango, rsvg, webp
#> Disabled features: fftw, ghostscript, x11 Created on 2018-12-14 by the reprex package (v0.2.1) Comments: 1. having to add 2. The following are ways to access frame information in different settings: Edit: Thomas explained to me that the counter may be accessed with |
For 1) You don't need to set grouping when using transition_manual, as there is really no tweeting happening at all To answer 2): if you simply want a counter for which frame you're at, then the |
Thanks Thomas. Oh I didn't realize there was a Do you mean there's a simpler way to obtain the "cumulative" effect? Right now, this is my understanding:
So it's easy enough to remember this:
But much harder to remember to also add I for one am likely to remember this, now that I've talked about it so much, I just think it's a bit of a hurdle for a beginner. But perhaps I've missed an easier way to do this (that is, Example 2 above)? |
There are many different ways to achieve seemingly identical results on. The different transitions differ, not in what type of output they can create, but in how they interpret the layer data and create an animation for that. In much the same way that "complaining" that you have to sort the data by x in order to make |
I see thanks Thomas. I'm not complaining, just giving feedback about a new user's experience with the package. My intention was just to give you constructive feedback. APOLOGIES if it sounded like a complain, it wasn't. On another matter: Example 5 crashed at around 1,000 points (two plots are created each with 1,000 points and it crashes on my 2017 MacBook Pro). It's not a complaint (!). Gifs with so many points were not such a good idea to begin with. :-) |
I know, hence the final parenthesis - I used "complain" for lack of better word... Your crash is related to the magick package when assembling the two plots. ImageMagick loads all images in to memory before assembling the gif, so at a certain point there are too many frames to handle... gifski is much better to handle this as it only have a single frame in memory at a time |
Oh thanks, I'll look into |
I just saw your
|
I've been a fan of
gganimate
. Great package! I am updating several animations I had made with the earlier API... I cannot seem to even get started. I have seen the wiki, but these examples are too advanced and I didn't manage to adapt them right away to my simple needs. I would like to suggest adding simpler examples to the README and/or wiki.Suggestion: (Help) Create a few simple examples for dummies:
In the
reprex
below, I suggest 4 or 5 examples that a newbie could use to get started. Please help me use the correct syntax in those cases where I haven't worked it out. Thanks!Below two basic plots to animate:
Created on 2018-12-11 by the reprex package (v0.2.1)
A convenience function to display GIFs side by side (used in the examples below).
The text was updated successfully, but these errors were encountered: