Site icon R-bloggers

Phyllotaxis3D, Belatedly

[This article was first published on R on R(e)Thinking, 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.

I coded my first R/Shiny app a month ago, but never wrote about it anywhere. Here’s the backstory.

What the heck is phyllotaxis, anyway?

As part of my exploration of the R world I came upon @aschinchon’s fantastic fronkonstin website. It’s a beautiful and creative display of mathematics and art, often pushing the limits of what can be done in a few lines of R code.

Shortly after, I noticed the launch of DataCamp’s projects section, and one of them was by Antonio on phyllotaxis. Phyllotaxis is the arrangement of leaves on a plant stem and often follows surprising mathematical arrangements. It’s a fun project to hone your ggplot2 skills while also creating some attractive spiral patterns.

That project inspired me to research 3D phyllotaxis patterns and whether I could create something in R to visualize them. I decided this would be an opportunity to create my first Shiny app in R. I found that none other than Stephen Wolfram had written about it in A New Kind of Science and created a Mathematica document to view them. While Mathematica is an awe-inspiring program that still seems ahead of its time, decades after it was released, I imagine that its proprietary nature has somewhat limited widespread adoption, and the document above requires a browser plug-in that few people will have likely installed and adds a barrier to usage. Shiny, which doesn’t require any kind of plug-in, seemed to be the perfect tool for the job.

I coded my Shiny app following the general approach of the Wolfram demonstration, but using the plotly package to create the 3D scatters. I tweaked some parameter ranges and default values, and added a slew of color palettes to view the 3D spirals in myriad ways.

Some of the results are here:

The Shiny App

Make your own 3D spirals by trying the app yourself here

If it doesn’t work it’s because all time has been used up for a free Shiny app instance at shinyapps.io. Try again soon.

The code is hosted on Github

And @dataandme’s Tweet

???? View phyllotaxis in 3D w/ @plotlygraphs in @cortinah's awesome 1st ✨ shiny app!https://t.co/sM2p3PFh0l #rstats #rshiny pic.twitter.com/pdSxIc7PBP

— Mara Averick (@dataandme) January 22, 2018

Thank you for the shout-out Mara – this app wouldn’t exist without the encouragement and work of the R community.

To leave a comment for the author, please follow the link and comment on their blog: R on R(e)Thinking.

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.