View source: R/trajectory_visualization.R
| export_animation | R Documentation |
This function is a helepr for gganimate's anim_save(), providing a
simplified, though less feature-rich, version of these functions. Animations
are saved as .gifs at the desired path. With this function,
publication-quality (high-resolution and smooth) animations are possible,
but take a long time to render.
export_animation(
anim_object,
path,
duration = 30,
fps = 10,
width = 7.5,
height = 5.5,
dpi = 100
)
anim_object |
A |
path |
A string representing the desired path and name at which to save animation. |
duration |
Optional. A numeric, in seconds, representing the length of
the animation. Default is |
fps |
Optional. The frames per second of the saved animation. Default
is |
width |
Optional. The width of the exported image, in inches. Default
is |
height |
Optional. The height of the exported image, in inches. Default
is |
dpi |
Optional. The resolution, in dots per inch, of the image. Default
is |
File saved to the desired directory.
lineE_traj <- new_transittraj_data("get_trajectory_fun")
# Set my parameters
my_features <- data.frame(name = c("Metro Center"),
distance = c(24556))
my_dist_range <- c(24000, 25000)
# Create `gganimate` object
anim_line <- plot_animated_line(trajectory = lineE_traj,
feature_distances = my_features,
route_color = "firebrick4",
label_field = "name",
label_alpha = 0.8,
label_pos = "right",
distance_lims = my_dist_range,
center_vehicles = TRUE,
timestep = 1)
# Create a place to store your file
my_file_name <- tempfile("my_animation", fileext = ".gif")
print(my_file_name)
# Run function: save animation locally
if (interactive()) {
# Note: Due to long processing times, animations will only be rendered &
# displayed if run during an interactive session. See `example()`.
export_animation(anim_object = anim_line,
path = my_file_name,
width = 4, height = 8, dpi = 150,
fps = 10, duration = 10)
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.