Animating a geom_col with ggplotly

I got help the other day dealing with ggplotly dates show as 19 thousand series of numbers.

Now, I want to animate this chart with a new column or columns with each additional days. Here is the code from the other post with only frame=activity_date now in the geo_column aes.

library(tidyverse)
library("lubridate")
library(plotly)
library(htmlwidgets)
library("reprex")


turtle_activity_gtm <-  read_csv("https://www.dropbox.com/s/7ubvhajvkhx53kc/mpt_act_rep_cum_fc_cum_nest.csv?dl=1")
#Above file has cumulative false crawls and cumulative nests added along with proper date formats.

start_date <- ymd("2022-04-15")
end_date <- ymd("2022-10-31")

ggstatic <-  turtle_activity_gtm |> filter(activity=="N") |>
  group_by(activity_date, species) |> 
  summarize(N = n()) |> 
  ggplot() +
  geom_col(aes(x = activity_date, y = N, fill = species, frame=activity_date),
           na.rm = TRUE,
           position = position_dodge2(preserve = "single")) +
  scale_x_date(breaks = c(seq.Date((start_date), (end_date), 
                                   by = '10 days'), end_date), 
               date_labels = "%m/%d",
               date_minor_breaks = "1 day",
               limits = c( start_date, end_date),
               expand = c(0,0)) 

ggplotly(ggstatic)

Below is a short screen capture of the partial animation where all columns are present with each day. I manually scroll the legend as it progresses. Yeah, there are those pesky days from the being of 1970 present. But right now, I am more interested in get the plot to grow with each successive day.

ggplotly_animate

Thanks,
Jeff

Hi these tutorial may be for you:
ggplotly:

  1. Create an interactive slope chart with the plotly and ggplot2 R packages (CC156) - YouTube
  2. Using R to make a 3D interactive figure showing climate change with plotly (CC223) - YouTube
  3. Using the plotly R package to create an interactive scatter plot (CC084) - YouTube

gganimate:

  1. Animate two synchronized figures in R with gganimate, magick, and ggplot2 (CC100) - YouTube
  2. Recreating animated climate temperature spirals in R with ggplot2 and gganimate (CC219) - YouTube
  3. Juneteenth 2021: Creating a data based movie in R with gganimate of lynchings (CC118) - YouTube
  4. Creating the NASA GISS animated climate spiral in R (CC220) - YouTube

This topic was automatically closed 42 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.