[This article was first published on R on kieranhealy.org, and kindly contributed to R-bloggers]. (You can report issue about the content on this page here)


Want to share your content on R-bloggers? click here if you have a blog, or here if you don’t.

Some Lissajous animations for Pi Day. Made with R, ggplot, and gganimate.

And the really not very efficient code that made them:

r
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
library(tidyverse)
library(gganimate)
library(transformr)

df_base <- tibble(
  id = seq(1, 1000, 1),
  t_vals = seq(0, 2 * pi, length.out = 1000))


circles <- function(t) {
  x01 <- cos(t * 1)
  y01 <- sin(t * 1)

  x02 <- cos(t * 2)
  y02 <- sin(t * 2)

  x03 <- cos(t * 3)
  y03 <- sin(t * 3)

  x04 <- cos(t * 4)
  y04 <- sin(t * 4)

  x05 <- cos(t * 5)
  y05 <- sin(t * 5)

  x06 <- cos(t * 6)
  y06 <- sin(t * 6)

  x07 <- cos(t * 7)
  y07 <- sin(t * 7)

  x08 <- cos(t * 8)
  y08 <- sin(t * 8)

  x09 <- cos(t * 9)
  y09 <- sin(t * 9)

  x10 <- cos(t * 10)
  y10 <- sin(t * 10)


  tibble(
    tick = seq_along(t),
    x01, x02, x03, x04, x05, x06, x07, x08, x09, x10,
    y01, y02, y03, y04, y05, y06, y07, y08, y09, y10
    )
}

df_out <- circles(t = df_base$t_vals)

df <- bind_cols(df_base, df_out) |>
  select(id, tick, everything()) |>
  pivot_longer(x01:x10, names_to = "x_group", values_to = "x") |>
  pivot_longer(y01:y10, names_to = "y_group", values_to = "y") |>
  mutate(x_group = str_remove(x_group, "x"),
         y_group = str_remove(y_group, "y")) |>
  unite("group_id", x_group, y_group, remove = FALSE)

out <- df |>
  ggplot(aes(x = x, y = y, color = group_id, group = group_id)) +
  geom_point(size = 3) +
  geom_path() +
  facet_grid(x_group ~ y_group) +
  coord_equal() +
  guides(color = "none") +
  theme_void() +
  transition_reveal(tick) +
  ease_aes("linear")



animate(out, duration = 30, fps = 24, height = 1080, width = 1080,
        renderer = ffmpeg_renderer())

anim_save(filename = "lissajous-fixed-lg-2.webm",
          height = 1080, width = 1080)
To leave a comment for the author, please follow the link and comment on their blog: R on kieranhealy.org.

R-bloggers.com offers daily e-mail updates about R news and tutorials about learning R and many other topics. Click here if you’re looking to post or find an R/data-science job.


Want to share your content on R-bloggers? click here if you have a blog, or here if you don’t.

Continue reading: Pi Day Circles

Implications and Future Developments Based On Lissajous Animations Made with R

The key point in the text is the usage of R statistical programming language, combined with libraries ggplot and gganimate, to create Lissajous animations. The importance of this development lies in the widening potential applications of these animations and the ongoing innovation within the field.

Long-Term Implications

Lissajous curves, visual representations of complex harmonic motion, have a wide array of applications – from physics and astronomy to music and digital signal processing. The increasing integration of the R language and its graphic capabilities signifies a huge shift in how these complex mathematical concepts can be visually represented, manipulated, and understood. This could herald a new era in the analysis and visualisation of complex data, particularly as it becomes more integral to numerous fields – from science to finance.

Future Developments

This trend of combining data visualisation and computation in one efficient language such as R is likely to persist, if not accelerate, in the future. With the rising interest and application of mathematical modeling in various sectors – including healthcare, energy, and the environment – the demand for accessible, user-friendly, and efficiently coded visualization tools can only grow.

Actionable Advice

  • Invest in R and its libraries: Staying on top of developments in this field will require a proficient understanding of R and its various libraries, such as ggplot and gganimate.
  • Prioritize Efficiency: The code used in the referenced text is self-admittedly not very efficient. Consequently, a focus should be placed on finding ways to improve its efficiency.
  • Keep an eye on developing trends: The merging of computation and visualisation holds promising potential for the future. By staying informed about advancements in the R community and the wider field, you can ensure you’re prepared to leverage new tools and methods as they emerge.

“The intersection between computation and visualization are where the most exciting developments are happening. Understanding and leveraging these tools today will give you a significant advantage tomorrow.”

Read the original article