Skip to content

Commit

Permalink
Add animations
Browse files Browse the repository at this point in the history
  • Loading branch information
n8layman committed Jul 22, 2024
1 parent a5a5f8f commit 6c61462
Show file tree
Hide file tree
Showing 5 changed files with 90 additions and 157 deletions.
14 changes: 9 additions & 5 deletions R/calc_outbreak_history.R
Original file line number Diff line number Diff line change
Expand Up @@ -181,8 +181,11 @@ get_outbreak_history_animation <- function(input_files,
output_dir = "outputs",
output_filename = "outbreak_history_2007.gif",
layers = NULL,
title = NULL,
...) {

title <- paste(title, '{current_frame}') |> stringr::str_squish()

# Create directory if it does not yet exist
dir.create(output_dir, recursive = TRUE, showWarnings = FALSE)

Expand All @@ -198,14 +201,15 @@ get_outbreak_history_animation <- function(input_files,
mutate(date = as.Date(date),
display_date = format(date, "%B %Y"))

# Left off here:
# labs(title = '{gsub(pattern = "[0-9]+-", replacement = "", closest_state)}')
p <- ggplot(df_long, aes(x=x, y=y, fill=value)) +
geom_raster() +
scale_fill_viridis_c(limits=c(min(df_long$value, na.rm=T), max(df_long$value, na.rm=T))) +
labs(title = '{current_frame}', x = "Longitude", y = "Latitude", fill = "Weight") +
scale_fill_viridis_c(limits=c(min(df_long$value, na.rm=T),
max(df_long$value, na.rm=T)),
trans = scales::sqrt_trans()) +
labs(title = title, x = "Longitude", y = "Latitude", fill = "Weight\n") +
theme_minimal() +
theme(text=element_text(size = 14))
theme(text=element_text(size = 14),
legend.title = element_text(vjust = 3))

# I can't get anim_save to work on my mac. Switching to ImageMagick rather than bother fixing it
# gifs save and render fine but can't be opened once saved. I tried re-installing gifski
Expand Down
2 changes: 2 additions & 0 deletions _targets.R
Original file line number Diff line number Diff line change
Expand Up @@ -165,11 +165,13 @@ dynamic_targets <- tar_plan(
tar_target(wahis_outbreak_history_recent_animation, get_outbreak_history_animation(input_files = c("data/outbreak_history_dataset/outbreak_history_recent_2007.tif"),
output_dir = "outputs",
output_filename = "outbreak_history_recent_2007.gif",
title = "Recent Outbreak History",
wahis_outbreak_history)), # Just included to enforce dependency with wahis_outbreak_history

tar_target(wahis_outbreak_history_old_animation, get_outbreak_history_animation(input_files = c("data/outbreak_history_dataset/outbreak_history_old_2007.tif"),
output_dir = "outputs",
output_filename = "outbreak_history_old_2007.gif",
title = "Old Outbreak History",
wahis_outbreak_history)), # Just included to enforce dependency with wahis_outbreak_history

# SENTINEL NDVI -----------------------------------------------------------
Expand Down
Loading

0 comments on commit 6c61462

Please sign in to comment.