gganimate

Using gganimate to export gif

天涯浪子 提交于 2019-12-19 14:25:06
问题 The package gganimate creates gifs (MWE code from here): library(ggplot2) #devtools::install_github('thomasp85/gganimate') library(gganimate) p <- ggplot(mtcars, aes(factor(cyl), mpg)) + geom_boxplot() + # Here comes the gganimate code transition_states( gear, transition_length = 2, state_length = 1 ) + enter_fade() + exit_shrink() + ease_aes('sine-in-out') How can export this gif now? In the previous (now archived) version of gganimate this was simple: gganimate(p, "output.gif") However, I

Control speed of a gganimation

╄→尐↘猪︶ㄣ 提交于 2019-12-17 19:35:50
问题 I want to slow the transition speed between states when using library(gganimate) . Here is a mini example: # devtools::install_github("thomasp85/gganimate") library(gganimate) # v0.9.9.9999 dat_sim <- function(t_state, d_state) { data.frame( x = runif(1000, 0, 1), y = runif(1000, 0, 1), t_state = t_state*d_state ) } dat <- purrr::map_df(1:100, ~ dat_sim(., 1)) ggplot(dat, aes(x, y)) + geom_hex(bins = 5) + theme_void() + lims(x = c(.3, .7), y = c(.3, .7)) + theme(legend.position = "none") +

How does gganimate order an ordered bar time-series?

江枫思渺然 提交于 2019-12-12 07:31:21
问题 I have a time-series of data, where I'm plotting diagnosis rates for a disease on the y-axis DIAG_RATE_65_PLUS , and geographical groups for comparison on the x-axis NAME as a simple bar graph. My time variable is ACH_DATEyearmon , which the animation is cycling through as seen in the title. df %>% ggplot(aes(reorder(NAME, DIAG_RATE_65_PLUS), DIAG_RATE_65_PLUS)) + geom_bar(stat = "identity", alpha = 0.66) + labs(title='{closest_state}') + theme(plot.title = element_text(hjust = 1, size = 22),

gganimate with changing scales (axis limits)

岁酱吖の 提交于 2019-12-11 03:03:52
问题 I'd like to create a gif using gganimate , but my axis ranges vary wildly in one frame. This is causing all subsequent frames to be squeezed. In ggplot2 's facets, there's an option to have scales="free" . Is there a way to have free scales in each frame of gganimate ? Here's an example: library(gapminder) library(ggplot2) library(gganimate) theme_set(theme_bw()) p <- ggplot(gapminder, aes(gdpPercap, lifeExp, size = pop, color = continent, frame = year)) + geom_point() + scale_x_log10()

How to gganimate a stacked bar graph?

☆樱花仙子☆ 提交于 2019-12-10 18:25:57
问题 I am trying to make a transition between four stacked bar graphs. The output is not quite what I expected and I haven't been able to figure if it's an error in my code or if it's a bug in gganimate R package. This is the data frame I use: df <- structure(list(name = c("variable", "variable", "variable", "variable", "variable", "variable", "variable", "variable", "variable", "variable", "variable", "variable", "variable"), groups = structure(c(3L, 3L, 3L, 3L, 2L, 2L, 2L, 1L, 1L, 1L, 4L, 4L, 4L

Change label of gganimate frame title

送分小仙女□ 提交于 2019-12-10 01:24:08
问题 Skimming through the options of gganimate that can be set when gg_animate() is called to render the animated sequence, it seems that there is no option to change the frame title so to make it clearer to the observer of what is the parameter that the frame is based on. In other words, suppose that frame = year in a layer: how do I make the frame's title be year: #### where #### is the year of the current frame? Am I missing something or is it a limitation of the gganimate library? How would

GGanimate: geom_text with numeric values animates at decimal numbers instead of integers

孤街醉人 提交于 2019-12-09 22:29:40
问题 Data <- data.frame(Time = c(1, 1, 1, 2, 2, 2, 3, 3, 3), Group = c("A", "B", "C", "A", "B", "C", "A", "B", "C"), Value = c(20, 10, 15, 20, 20, 20, 30, 25, 35)) I have three Groups with Values at three different points in Time . library(ggplot2) library(gganimate) p <- ggplot(Data, aes(Group, Value)) + geom_col(position = "identity") + geom_text(aes(label = Value), vjust = -1) + coord_cartesian(ylim = c(0, 40)) + transition_time(Time) p The above code produces the animation for the

How to create and display an animated GIF in Shiny?

空扰寡人 提交于 2019-12-09 04:53:22
问题 I'm able to load a saved file as an image but unable to use gganimate to do it directly. Alternate ways of rendering GIFs would be nice to know but knowing how to render gganimate specifically would really solve my problem. library(gapminder) library(ggplot2) library(shiny) library(gganimate) theme_set(theme_bw()) ui <- basicPage( plotOutput("plot1") ) server <- function(input, output) { output$plot1 <- renderPlot({ p = ggplot(gapminder, aes(gdpPercap, lifeExp, size = pop, color = continent,

gganimate: include additional variable other than states level variable or frame in title expression

本秂侑毒 提交于 2019-12-07 04:10:37
问题 I'd like to insert another column value of my data into a gganimate animation title. Example, here the states level variable is x and I'd like to add to title variable y : df <- tibble(x = 1:10, y = c('a', 'a', 'b', 'd', 'c', letters[1:5])) df A tibble: 10 x 2 x y <int> <chr> 1 1 a 2 2 a 3 3 b 4 4 d 5 5 c 6 6 a 7 7 b 8 8 c 9 9 d 10 10 e This works as expected: ggplot(df, aes(x, x)) + geom_point() + labs(title = '{closest_state}') + transition_states(x, transition_length = 0.1, state_length =

gganimate: include additional variable other than states level variable or frame in title expression

邮差的信 提交于 2019-12-05 10:48:06
I'd like to insert another column value of my data into a gganimate animation title. Example, here the states level variable is x and I'd like to add to title variable y : df <- tibble(x = 1:10, y = c('a', 'a', 'b', 'd', 'c', letters[1:5])) df A tibble: 10 x 2 x y <int> <chr> 1 1 a 2 2 a 3 3 b 4 4 d 5 5 c 6 6 a 7 7 b 8 8 c 9 9 d 10 10 e This works as expected: ggplot(df, aes(x, x)) + geom_point() + labs(title = '{closest_state}') + transition_states(x, transition_length = 0.1, state_length = 0.1) This fails: ggplot(df, aes(x, x)) + geom_point() + labs(title = '{closest_state}, another_var: {y}