Lijia Yu
(yu@lijiayu.net / GitHub
/ Twitter) A master candidate majoring in Bioinformatics at Beijing Institute of Genomics.
This article shows you how to draw an egg with R. I wrote this article after I learned to use the
animation package for one week. So I will show you the simplest
way to create an animated figure. The only function used in this package is ani.pause().
Let’s get started!
A simple egg
The equations that define an egg are:
In the figure below, let’s swap the x axis and y axis for an egg in the vertical direction.
The ani.pause() function is called to pause for a time interval (by default specified in
ani.options('interval')) and flush the current device. We draw a egg with with different angles
in 30 images, and you will see the egg rotating below:
Another example:
3D eggs
If you want to draw a 3D egg. The rgl package can help you do it. The 3D egg is just a
perturbation of a sphere. The function is: