[This article was first published on » R, 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.
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.
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)
To leave a comment for the author, please follow the link and comment on their blog: » R.
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.