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

Slightly improved Readme examples #258

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions README.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,14 @@ added to the plot object in order to customise how it should change with time.
## An Example
All of the above might seem a bit abstract. Let's try with a contrived example:

```{r, message=FALSE}
```{r example_mtcars, message=FALSE}
library(ggplot2)
library(gganimate)

ggplot(mtcars, aes(factor(cyl), mpg)) +
geom_boxplot() +
# Here comes the gganimate code
labs(title = 'Gears: {closest_state}') +
transition_states(
gear,
transition_length = 2,
Expand Down Expand Up @@ -82,7 +83,7 @@ devtools::install_github('thomasp85/gganimate')
It is impossible to cover everything possible with `gganimate` in a README, but
animations are fun, so let's at least have one more:

```{r}
```{r example_gapminder}
library(gapminder)

ggplot(gapminder, aes(gdpPercap, lifeExp, size = pop, colour = country)) +
Expand Down Expand Up @@ -127,7 +128,7 @@ the `animate()` function you can control the animation format, and `gganimate`
comes with a bunch (and you can write your own). To create video files you can
e.g. use the `ffmpeg_renderer()`:

```{r, eval=FALSE}
```{r example_airquality, eval=FALSE}
p <- ggplot(airquality, aes(Day, Temp)) +
geom_line(size = 2, colour = 'steelblue') +
transition_states(Month, 4, 1) +
Expand Down
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ library(gganimate)
ggplot(mtcars, aes(factor(cyl), mpg)) +
geom_boxplot() +
# Here comes the gganimate code
labs(title = 'Gears: {closest_state}') +
transition_states(
gear,
transition_length = 2,
Expand All @@ -51,7 +52,7 @@ ggplot(mtcars, aes(factor(cyl), mpg)) +
ease_aes('sine-in-out')
```

![](man/figures/README-unnamed-chunk-2-1.gif)<!-- -->
![](man/figures/README-example_mtcars-1.gif)<!-- -->

Here we take a simple boxplot of fuel consumption as a function of
cylinders and lets it transition between the number of gears available
Expand Down Expand Up @@ -94,7 +95,7 @@ ggplot(gapminder, aes(gdpPercap, lifeExp, size = pop, colour = country)) +
ease_aes('linear')
```

![](man/figures/README-unnamed-chunk-4-1.gif)<!-- -->
![](man/figures/README-example_gapminder-1.gif)<!-- -->

In this example we see the use of `transition_time()` which can be used
with continuous variables such as `year`. With this transition it is not
Expand Down
Binary file added man/figures/README-example_gapminder-1.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added man/figures/README-example_mtcars-1.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.