#
#
R#
Show code cell source
# Loading libraries
library(ggplot2)
library(gganimate)
# Defining parameters for a particle in a magnetic field
t <- seq(0, 10, by = 0.1)
x <- sin(t)
y <- cos(t)
# Creating a data frame to hold the values
particle_data <- data.frame(
time = t,
x = x,
y = y
)
# Creating the plot using ggplot2 and gganimate
plot <- ggplot(particle_data, aes(x = x, y = y)) +
geom_path(aes(group = 1), color = 'gray') + # Making sure all points are in the same group
geom_point(size = 4) +
labs(title = "Particle in a Magnetic Field",
x = "X Axis",
y = "Y Axis") +
theme_minimal() +
coord_fixed(ratio = 1) +
transition_reveal(time)
# Create and save the animation
animate(plot, renderer = gifski_renderer("particle_animation.gif"))
Show code cell output
`geom_path()`: Each group consists of only one observation.
ℹ Do you need to adjust the group aesthetic?
`geom_path()`: Each group consists of only one observation.
ℹ Do you need to adjust the group aesthetic?
Rendering [>--------------------------------------------] at 14 fps ~ eta: 7s
Rendering [=>-------------------------------------------] at 15 fps ~ eta: 6s
Rendering [==>------------------------------------------] at 16 fps ~ eta: 6s
Rendering [==>------------------------------------------] at 15 fps ~ eta: 6s
Rendering [===>-----------------------------------------] at 15 fps ~ eta: 6s
Rendering [===>-----------------------------------------] at 16 fps ~ eta: 6s
Rendering [====>----------------------------------------] at 16 fps ~ eta: 6s
Rendering [====>----------------------------------------] at 16 fps ~ eta: 5s
Rendering [=====>---------------------------------------] at 16 fps ~ eta: 5s
Rendering [======>--------------------------------------] at 16 fps ~ eta: 5s
Rendering [======>--------------------------------------] at 17 fps ~ eta: 5s
Rendering [=======>-------------------------------------] at 17 fps ~ eta: 5s
Rendering [========>------------------------------------] at 17 fps ~ eta: 5s
Rendering [=========>-----------------------------------] at 17 fps ~ eta: 5s
Rendering [==========>----------------------------------] at 17 fps ~ eta: 4s
Rendering [===========>---------------------------------] at 17 fps ~ eta: 4s
Rendering [============>--------------------------------] at 17 fps ~ eta: 4s
Rendering [=============>-------------------------------] at 17 fps ~ eta: 4s
Rendering [==============>------------------------------] at 17 fps ~ eta: 4s
Rendering [===============>-----------------------------] at 17 fps ~ eta: 4s
Rendering [================>----------------------------] at 17 fps ~ eta: 4s
Rendering [=================>---------------------------] at 17 fps ~ eta: 4s
Rendering [=================>---------------------------] at 17 fps ~ eta: 3s
Rendering [==================>--------------------------] at 17 fps ~ eta: 3s
Rendering [==================>--------------------------] at 16 fps ~ eta: 3s
Rendering [===================>-------------------------] at 16 fps ~ eta: 3s
Rendering [====================>------------------------] at 17 fps ~ eta: 3s
Rendering [=====================>-----------------------] at 17 fps ~ eta: 3s
Rendering [======================>----------------------] at 17 fps ~ eta: 3s
Rendering [=======================>---------------------] at 17 fps ~ eta: 3s
Rendering [========================>--------------------] at 17 fps ~ eta: 3s
Rendering [=========================>-------------------] at 17 fps ~ eta: 3s
Rendering [=========================>-------------------] at 17 fps ~ eta: 2s
Rendering [==========================>------------------] at 17 fps ~ eta: 2s
Rendering [===========================>-----------------] at 17 fps ~ eta: 2s
Rendering [============================>----------------] at 17 fps ~ eta: 2s
Rendering [=============================>---------------] at 17 fps ~ eta: 2s
Rendering [==============================>--------------] at 17 fps ~ eta: 2s
Rendering [===============================>-------------] at 17 fps ~ eta: 2s
Rendering [================================>------------] at 17 fps ~ eta: 2s
Rendering [================================>------------] at 17 fps ~ eta: 1s
Rendering [=================================>-----------] at 17 fps ~ eta: 1s
Rendering [==================================>----------] at 18 fps ~ eta: 1s
Rendering [===================================>---------] at 18 fps ~ eta: 1s
Rendering [====================================>--------] at 18 fps ~ eta: 1s
Rendering [=====================================>-------] at 18 fps ~ eta: 1s
Rendering [======================================>------] at 18 fps ~ eta: 1s
Rendering [=======================================>-----] at 18 fps ~ eta: 1s
Rendering [========================================>----] at 18 fps ~ eta: 1s
Rendering [========================================>----] at 18 fps ~ eta: 0s
Rendering [=========================================>---] at 18 fps ~ eta: 0s
Rendering [==========================================>--] at 18 fps ~ eta: 0s
Rendering [===========================================>-] at 18 fps ~ eta: 0s
Rendering [============================================>] at 18 fps ~ eta: 0s
Rendering [=============================================] at 18 fps ~ eta: 0s
Show code cell source
static_plot <- ggplot(particle_data, aes(x = x, y = y)) +
geom_path(aes(group = 1), color = 'gray') +
geom_point(size = 4) +
labs(title = "Particle in a Magnetic Field", x = "X Axis", y = "Y Axis") +
theme_minimal() +
coord_fixed(ratio = 1)
# print(static_plot)
1+5
6
"hey"
'hey'
x = 5
x
5