Here you will find daily news and tutorials about R, contributed by over 750 bloggers.
There are many ways to follow us - By e-mail:On Facebook: If you are an R blogger yourself you are invited to add your own R content feed to this site (Non-English R bloggers should add themselves- here)

(This article was first published on » R, and kindly contributed to R-bloggers)

I came across the butterfly curve, which was discovered by Temple Fay. The butterfly curve is produced by a parametric equation where: x = sin(t) * (e^cos(t)-2cos(λt)-sin(t/12)^5) and y = cos(t) * (e^cos(t)-2cos(λt)-sin(t/12)^5).
Where t stands for time and λ for a user input variable.

I used ggplot to create a plot of the butterfly curve with a background of the same color pattern. After sourcing the function, the user can vary the number of background points, as well as the butterfly curves.

library(ggplot2)
source("https://raw.githubusercontent.com/danielmarcelino/SciencesPo/master/R/butterfly.R")
> p1 = butterfly(10, 100, title="10 x 100")
Date of Analysis: Wed Oct 07 2015
Computation time: 0.009749889
-----------------------------------
> p2 = butterfly(10, 200, title="10 x 200")
Date of Analysis: Wed Oct 07 2015
Computation time: 0.01240611
-----------------------------------
> p3 = butterfly(10, 500, title="100 x 500")
Date of Analysis: Wed Oct 07 2015
Computation time: 0.02488399
-----------------------------------
> p4 = butterfly(100, 1000, title="100 x 1000")
Date of Analysis: Wed Oct 07 2015
Computation time: 0.01444697
-----------------------------------
multiplot(p1,p2,p3,p4, ncols = 2)

Related

To leave a comment for the author, please follow the link and comment on their blog: » R.