LIS 4317 Data Visualization: Animated Graphics

LIS 4317 Data Visualization: Animated Graphics
Figure 1: Animated plot of atoms in a protein.

Most data visualizations are static, and while one can visualize a fair number of variables, however it can still be limited. Since we are in the 21st century, we can take advantage of our access to computer graphics and reveal more about the data by adding motion. This could be through the adding of a literal time variable, or it could involve the spinning of an axis in a 3D plot, such as the animation above in Figure 1. To make the above visualization I used the protein8k package which can be found here, to write an R script which you can find on my GitHub here, or follow the links at the bottom of this post.

To begin I installed and loaded the protein8k package. This is a package I have been developing with Dr. Alon Friedman for the visualization of proteins. To install and load the package, you can use the following R code.

#Install protein8k
devtools::install_github("SimonLiles/protein8k", build_vignettes = TRUE)

#Load the library
library(protein8k)
Code language: R (r)

To make the visualization I will be using the P53 Tetramerization data set that comes preloaded with the package. This is a smallish protein with about 900 atoms and has interesting structures inside it. The data set is made from a Protein Data Bank file. When it is plotted using plot3D() the atomic record, or location of each atom is plotted into a 3D space.

We can make a simple plot using the following line of code. The type of drawing is specified to points, and the grouping variable residue_name will color the points by the name of each residue in the protein. The screen argument is used to orientate the plot.

#Make a basic plot
plot3D(p53_tetramerization, type = "p", groups = residue_name, 
       screen = list(z = 30, x = -60, y = 0))
Code language: R (r)

This produces the following visualization.

Figure 2: Simple 3D plot of the P53 Tetramerization protein.

This visualization looks interesting, however it is messy and it is hard to see any kind of patterns. While we could create a separate plot and fix it to a different angle using the screen argument, that will be hard and laborious. This is one area where animated graphics shine through. By spinning the plot, a more complete understanding of the protein structure can be gained. With the plot3D() function we can make the plot spin by setting the argument animated to TRUE.

#Make an animated plot
plot3D(p53_tetramerization, type = "p", groups = residue_name, animated = TRUE)
Code language: R (r)

This will make the animated visual that is in Figure 1. Running the above code will only generate the visual in the viewer. If you want to save the visualization, you need to assign it to an R object, and then using the magick package, you can save it as a GIF.

#Save the plot to an R object
plot_animated <- plot3D(p53_tetramerization, type = "p", groups = residue_name, 
                        animated = TRUE)

#Save animated plot to a .gif
require(magick)
image_write(plot_animated, path = "LIS4317Mod13Animation.gif")
Code language: R (r)

By animating the 3D plot, it is much easier to see different structures that exist, and the clusters become more apparent. In Figure 2 the protein seems to just be a blob, but when it was animated in Figure 1, the different branches and trunks are more obvious.

Depending on the data you could also add movement to the points to indicate change, for example change over time, and it may reveal new patterns. I also find animated visuals to be more visually engaging, and they look cool.

Links

R Script on GitHub: https://github.com/SimonLiles/LIS4317DataVisualization/blob/main/LIS4317Mod13.R

protein8k Package: https://github.com/SimonLiles/protein8k