Here is an example reprex
using transition_time
and also datapasta
to show you how you can share the data. In your reprex
I would recommend not putting the actual datapasta::dpasta
call into the reprex
, but just do something like what is shown below where you assign the output to a variable.
library(tidyverse)
library(gganimate)
library(datapasta)
library(gapminder)
gapminder::gapminder %>%
filter(country %in% c("United States", "Canada")) %>%
datapasta::dpasta()
#> Warning in tribble_construct(input_table, oc = output_context): Column(s)
#> 1,2 have been converted from factor to character in tribble output.
#> tibble::tribble(
#> ~country, ~continent, ~year, ~lifeExp, ~pop, ~gdpPercap,
#> "Canada", "Americas", 1952L, 68.75, 14785584L, 11367.16112,
#> "Canada", "Americas", 1957L, 69.96, 17010154L, 12489.95006,
#> "Canada", "Americas", 1962L, 71.3, 18985849L, 13462.48555,
#> "Canada", "Americas", 1967L, 72.13, 20819767L, 16076.58803,
#> "Canada", "Americas", 1972L, 72.88, 22284500L, 18970.57086,
#> "Canada", "Americas", 1977L, 74.21, 23796400L, 22090.88306,
#> "Canada", "Americas", 1982L, 75.76, 25201900L, 22898.79214,
#> "Canada", "Americas", 1987L, 76.86, 26549700L, 26626.51503,
#> "Canada", "Americas", 1992L, 77.95, 28523502L, 26342.88426,
#> "Canada", "Americas", 1997L, 78.61, 30305843L, 28954.92589,
#> "Canada", "Americas", 2002L, 79.77, 31902268L, 33328.96507,
#> "Canada", "Americas", 2007L, 80.653, 33390141L, 36319.23501,
#> "United States", "Americas", 1952L, 68.44, 157553000L, 13990.48208,
#> "United States", "Americas", 1957L, 69.49, 171984000L, 14847.12712,
#> "United States", "Americas", 1962L, 70.21, 186538000L, 16173.14586,
#> "United States", "Americas", 1967L, 70.76, 198712000L, 19530.36557,
#> "United States", "Americas", 1972L, 71.34, 209896000L, 21806.03594,
#> "United States", "Americas", 1977L, 73.38, 220239000L, 24072.63213,
#> "United States", "Americas", 1982L, 74.65, 232187835L, 25009.55914,
#> "United States", "Americas", 1987L, 75.02, 242803533L, 29884.35041,
#> "United States", "Americas", 1992L, 76.09, 256894189L, 32003.93224,
#> "United States", "Americas", 1997L, 76.81, 272911760L, 35767.43303,
#> "United States", "Americas", 2002L, 77.31, 287675526L, 39097.09955,
#> "United States", "Americas", 2007L, 78.242, 301139947L, 42951.65309
#> )
df <- tibble::tribble(
~country, ~continent, ~year, ~lifeExp, ~pop, ~gdpPercap,
"Canada", "Americas", 1952L, 68.75, 14785584L, 11367.16112,
"Canada", "Americas", 1957L, 69.96, 17010154L, 12489.95006,
"Canada", "Americas", 1962L, 71.3, 18985849L, 13462.48555,
"Canada", "Americas", 1967L, 72.13, 20819767L, 16076.58803,
"Canada", "Americas", 1972L, 72.88, 22284500L, 18970.57086,
"Canada", "Americas", 1977L, 74.21, 23796400L, 22090.88306,
"Canada", "Americas", 1982L, 75.76, 25201900L, 22898.79214,
"Canada", "Americas", 1987L, 76.86, 26549700L, 26626.51503,
"Canada", "Americas", 1992L, 77.95, 28523502L, 26342.88426,
"Canada", "Americas", 1997L, 78.61, 30305843L, 28954.92589,
"Canada", "Americas", 2002L, 79.77, 31902268L, 33328.96507,
"Canada", "Americas", 2007L, 80.653, 33390141L, 36319.23501,
"United States", "Americas", 1952L, 68.44, 157553000L, 13990.48208,
"United States", "Americas", 1957L, 69.49, 171984000L, 14847.12712,
"United States", "Americas", 1962L, 70.21, 186538000L, 16173.14586,
"United States", "Americas", 1967L, 70.76, 198712000L, 19530.36557,
"United States", "Americas", 1972L, 71.34, 209896000L, 21806.03594,
"United States", "Americas", 1977L, 73.38, 220239000L, 24072.63213,
"United States", "Americas", 1982L, 74.65, 232187835L, 25009.55914,
"United States", "Americas", 1987L, 75.02, 242803533L, 29884.35041,
"United States", "Americas", 1992L, 76.09, 256894189L, 32003.93224,
"United States", "Americas", 1997L, 76.81, 272911760L, 35767.43303,
"United States", "Americas", 2002L, 77.31, 287675526L, 39097.09955,
"United States", "Americas", 2007L, 78.242, 301139947L, 42951.65309
)
p <- df %>%
ggplot(aes(x = year, y = lifeExp, color = country)) +
geom_path() +
geom_point() +
facet_grid(~country) +
transition_reveal(id = year, along = year) +
ease_aes("linear")
animate(p, 100, 20)
Created on 2018-12-18 by the reprex package (v0.2.0).