Cannibus Curve with ggplot2
[This article was first published on R on Chi's Impe[r]fect Blog, 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.
Starting today, recreational weed is legal in Canada. This news has some how lead me to find Cannibus Curve, a mathmatical equation to draw Cannibus….!!!
So to celebrate? being 2nd country in the world (1st was Uruguay) to legalize the green stuff for fun, I decided I’ll try drawing cannibus curve with ggplot. Here’s the final results.
Here’s the step I took, because I couldn’t really understand the mathmatical equation, so I’ve break it down step by step to sort of understand what each part of equation is doing.
library(tidyverse) cannibus <- tibble( t = seq(-pi,pi, length.out=1000), r1 = (1+.9*cos(8*t)), ## this will draw 8 petals ## this number determines number of leafs! r2 = r1 * (1+.1*cos(24*t)), ## this make it pointy r3 = r2 * (.9+0.5*cos(200*t)), ## this makes it jaggy r4 = r3 * (1+sin(t)), ## Hmm.. I think I want to rorate it 90 degree... r4_alt = r3 * (1+sin(t-pi/2)), ## one way to do it... r = (1+.9*cos(8*t)) * (1+.1*cos(24*t)) * (.9+0.5*cos(200*t)) * (1+sin(t)) ## Put all in line line! ) cannibus %>% ggplot(aes(x=t, y=r1)) + geom_path(color="#7ABA71", size=2) + coord_polar() + theme_void(base_family="Roboto Condensed") + labs(title = "(1+.9*cos(8*t) draws 8 petals")
cannibus %>% ggplot(aes(x=t, y=r2)) + geom_path(color="#7ABA71", size=2) + coord_polar() + theme_void(base_family="Roboto Condensed") + labs(title = "(1+.9*cos(8*t) * * (1+.1*cos(24*t)) makes the tip pointy")
cannibus %>% ggplot(aes(x=t, y=r3)) + geom_path(color="#7ABA71", size=0.5) + coord_polar() + theme_void(base_family="Roboto Condensed") + labs(title = "(1+.9*cos(8*t) * * (1+.1*cos(24*t)) * (.9+0.5*cos(200*t)) makes zaggy")
cannibus %>% ggplot(aes(x=t, y=r4)) + geom_path(color="#7ABA71", size=0.5) + coord_polar(start=pi/2) + theme_void(base_family="Roboto Condensed") + labs(title = "(1+.9*cos(8*t) * * (1+.1*cos(24*t)) * (.9+0.5*cos(200*t)) * (1+sin(t)) - OK Cool, Now 2 leaves are small!", subcaption="Notice I used start=pi/2 to rotate!")
cannibus %>% ggplot(aes(x=t, y=r)) + geom_polygon(fill="#499b4a", color="#74Ba71", size=0.1) + coord_polar(theta="x", start=pi/2) + theme_void(base_family="Roboto Condensed") + labs(title = "Instead of using geom_path, I used geom_polygon")
I couldn’t figure out how to “crop” the polar coordinate image, so there’s lots of white space on final image, but I like my little cannibus!
To leave a comment for the author, please follow the link and comment on their blog: R on Chi's Impe[r]fect Blog.
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.