Module # 13

Your assignment:

Create a simple animation and discussion the result in your blog posting. 
Reference to Yihui Xie's and animation R package website, click here. A note, his package now available via CRAM repository and not GitHub.  For Bryan's blog posting on Animation in R, click here 
A note: In order to post your work on blog, you need to save your animation.
The code for saving the image you created in R is as follow:
saveGIF({
    for (i in 1:10) plot(runif(10), ylim = 0:1)
})



Working on this assignment was incredibly interesting. Before this module, I had no idea we could create animations through R studio. 


Below is an animation for the code that was given for this assignment. 

> saveGIF({
+   for (i in 1:10) plot(runif(10), ylim = 0:1)
+ })




Now I will focus on my rendition of an animation through R. 





The first animation I created was a relatively simple one where I demonstrated an investment account after a considerable amount of time. Over time, you can see a direct relationship between the amount of dollars earned through the years. The green arrow represents that steadily growing rate. 


> saveGIF({
+   for (i in 1:20) {
+     plot(0, 0, type = "n", xlim = c(0, 20), ylim = c(0, 20),
+          xlab = "Time", ylab = "Invested Stocks", main = "Investments")
+     arrows(0, 0, i, i, lwd = 3, col = "darkgreen")
+   }
+ })




The next animation I created was a little different. Using extra research, I incorporated the use of enter_fade() and exit_fade(). I wanted to to simulate a series of bar plots. Bar plots are visualizations we have extensively used throughout this course. My scenario deals with four quarters from the years 2021 to 2025. From this animation, we can see each quarter and how it performed. I believe this is a vital method in demonstrating trends. Not only is it easy to understand with the usage of color and simplicity, it is also engaging. I believe this example is a major reason as to why visualizations are important in representing data. 



> df <- data.frame(year = rep(2021:2025, each = 4), 
+                  Quarters = rep(c("Q1", "Q2", "Q3", "Q4"),times = 5),  
+                  Output = c(23, 33, 44, 19, 29, 27, 15, 40, 22, 31, 24, 42, 17, 25, 19,
+                             29, 32, 26, 20, 22))
> 
> plot <- ggplot(df, aes(Quarters, Output, fill = Quarters)) +  
+   geom_bar(stat = "identity") +  
+   scale_fill_manual(values = c("#FAD0C4", 
+                                "#E6A8D7",
+                                "#87CEEB",
+                                "#A3D9B1")) +  
+   theme_minimal() + 
+   labs(title = "Year: {closest_state}") 
> 
> animated_plot <- plot + transition_states(year, 
+                                     transition_length = 1, 
+                                     state_length = 1) + 
+   enter_fade() + 
+   exit_fade() + 
+   ease_aes("linear") 
> 
> animated_plot




Overall, the usage of animation in Rstudio is something I wish I've known earlier. Rstudio deals heavily with data and data can be furthered through effective depiction. Showing trends through simple animation invites greater understanding and appreciation for patterns, relationships, and correlations.   


Comments

Popular posts from this blog

Final Project

Module # 12