Introduction
manimR brings the power of mathematical animation to R, making it as easy to create stunning visualizations as it is to create plots with ggplot2. Inspired by Grant Sanderson’s manim (the engine behind 3Blue1Brown), manimR provides a tidyverse-friendly API for creating animations.
This vignette will walk you through the basics of creating your first animation.
Installation
# Install from CRAN (when available)
install.packages("manimR")
# Or install the development version from GitHub
# install.packages("pak")
pak::pak("Reyanda/manimR")Your First Animation
Let’s create a simple animation that displays text:
library(manimR)
scene("hello_world") %>%
add_text("Hello, manimR!", size = 72) %>%
write_in(duration = 2) %>%
pause(1) %>%
fade_out(duration = 1) %>%
render(output = "hello_world.mp4")This creates a 4-second animation where:
- Text appears with a writing effect (2 seconds)
- The text stays on screen (1 second)
- The text fades out (1 second)
Core Concepts
Scenes
A scene is your animation canvas. Everything you want to animate must be added to a scene:
# Create a basic scene
s <- scene("my_animation")
# Create a high-definition scene
s_hd <- scene("my_hd_animation", width = 3840, height = 2160, fps = 60)
# Create a 3D scene
s_3d <- scene_3d("my_3d_animation")Objects
Objects are the visual elements in your scene.
manimR supports: - Text: add_text() - LaTeX math:
add_latex() - Shapes: add_circle(),
add_rectangle(), add_line(),
add_arrow() - Images: add_image()
scene("shapes") %>%
add_circle(radius = 1, color = "blue", fill_color = "lightblue") %>%
grow_from_center() %>%
pause(1) %>%
add_rectangle(width = 3, height = 2, position = c(3, 0, 0)) %>%
grow_from_center() %>%
render()Animations
Animations control how objects appear and change:
- Appearance:
write_in(),fade_in(),grow_from_center() - Disappearance:
fade_out(),shrink_to_center() - Effects:
flash(),indicate(),pulse(),wiggle()
Transformations
Transformations change objects from one state to another:
- Movement:
move_to(),shift() - Rotation:
rotate() - Scaling:
scale_object() - Morphing:
transform_to(),morph()
Working with LaTeX
manimR has first-class support for LaTeX mathematical notation:
scene("latex_demo") %>%
add_latex("\\int_0^\\infty e^{-x^2} dx = \\frac{\\sqrt{\\pi}}{2}") %>%
write_in(duration = 3) %>%
pause(1) %>%
highlight_term("e^{-x^2}", color = "#FF6B6B") %>%
pause(0.5) %>%
highlight_term("\\frac{\\sqrt{\\pi}}{2}", color = "#4ECDC4") %>%
render()Note: Full LaTeX rendering requires LaTeX to be installed on your system. Install TinyTeX for a minimal LaTeX distribution.
The Pipe Workflow
manimR is designed to work seamlessly with the tidyverse pipe
(%>%):
library(manimR)
scene("pipe_demo") %>%
# Add objects
add_text("Welcome!", position = c(0, 3, 0), size = 48) %>%
write_in() %>%
# Add more content
add_latex("f(x) = x^2", position = c(0, 0, 0)) %>%
write_in() %>%
# Transform
pause(1) %>%
transform_to("f(x) = x^3", duration = 1.5) %>%
# Finish
pause(1) %>%
render(format = "mp4", quality = "high")Rendering Options
Control output format and quality:
# Quick preview (low quality, fast)
scene("demo") %>%
add_text("Preview") %>%
write_in() %>%
preview()
# High-quality MP4
scene("demo") %>%
add_text("High Quality") %>%
write_in() %>%
render(format = "mp4", quality = "high", fps = 60)
# Animated GIF
scene("demo") %>%
add_text("GIF Export") %>%
write_in() %>%
render(format = "gif", quality = "medium")
# 4K video
scene("demo") %>%
add_text("4K") %>%
write_in() %>%
render(format = "mp4", quality = "4K")Using Templates
manimR includes pre-built templates for common scenarios:
# List available templates
list_templates()
# Use a theorem template
use_template("theorem_proof") %>%
set_theorem("Pythagorean Theorem", "a^2 + b^2 = c^2") %>%
set_proof_steps(list(
"Consider a right triangle with legs a and b",
"The hypotenuse has length c",
"Area of squares: a^2, b^2, and c^2",
"By the theorem: a^2 + b^2 = c^2"
)) %>%
customize(color_scheme = "academic") %>%
render()Next Steps
Now that you know the basics, explore these topics:
-
vignette("mathematical-notation"): Advanced LaTeX techniques -
vignette("transformations"): Complex transformations and morphing -
vignette("tidyverse-integration"): Data-driven animations -
vignette("ggplot2-conversion"): Converting ggplot2 to animations
Getting Help
- Documentation: https://Reyanda.github.io/manimR
- GitHub Issues: https://github.com/Reyanda/manimR/issues
- Discord Community: https://discord.gg/manimR