Introduction
manimR is designed to work seamlessly with the tidyverse ecosystem. This vignette shows how to create data-driven animations, integrate with ggplot2, and use tidy data workflows. ## Pipe-Friendly Design
manimR uses the magrittr pipe (%>%) throughout:
Data-Driven Animations
ggplot2 Integration
Convert existing ggplot2 visualizations to manimR scenes:
library(ggplot2)
# Create a ggplot
p <- ggplot(mtcars, aes(mpg, wt, color = factor(cyl))) +
geom_point(size = 3) +
theme_minimal() +
labs(title = "MPG vs Weight", color = "Cylinders")
# Convert to manimR
convert_ggplot_to_manim(p, animate_build = TRUE) %>%
render()Working with Grouped Data
Animate data that changes over groups or time:
library(dplyr)
# Sample grouped data
group_data <- tibble(
category = rep(c("A", "B", "C"), each = 4),
quarter = rep(1:4, 3),
value = c(10, 15, 20, 25, # A
8, 12, 18, 22, # B
12, 14, 16, 20) # C
)
# Create animation showing each group
scene("grouped_animation") %>%
add_text("Sales by Category", position = c(0, 3.5, 0), size = 48) %>%
write_in() %>%
pause(0.5)
# Add each group's data
for (cat in c("A", "B", "C")) {
cat_data <- filter(group_data, category == cat)
scene %>%
add_text(paste("Category:", cat), position = c(-4, 2.5, 0)) %>%
fade_in() %>%
# Add visualization for this category
pause(2) %>%
fade_out()
}Animating Data Transformations
Show data pipeline steps:
scene("data_pipeline") %>%
# Show original data
add_text("Raw Data", position = c(0, 3, 0), size = 48) %>%
write_in() %>%
pause(1) %>%
# Show filtering
shift(c(0, -1, 0)) %>%
add_text("filter(year == 2020)", position = c(0, 2, 0),
color = "#4CAF50", size = 36) %>%
fade_in() %>%
pause(1) %>%
# Show grouping
add_text("group_by(region)", position = c(0, 1, 0),
color = "#2196F3", size = 36) %>%
fade_in() %>%
pause(1) %>%
# Show summarizing
add_text("summarise(total = sum(sales))", position = c(0, 0, 0),
color = "#FF9800", size = 36) %>%
fade_in() %>%
pause(1) %>%
render()Using purrr for Multiple Animations
Generate multiple related animations:
library(purrr)
# Create animations for different variables
variables <- c("mpg", "hp", "wt")
animations <- map(variables, function(var) {
scene(paste0(var, "_distribution")) %>%
add_text(paste("Distribution of", toupper(var)),
position = c(0, 3, 0), size = 48) %>%
write_in() %>%
# Add histogram animation here
pause(2) %>%
render(output = paste0(var, "_dist.mp4"))
})