X-Git-Url: http://git.vanrenterghem.biz/www2.vanrenterghem.biz.git/blobdiff_plain/9d5cad4353459e7fa815d6a8a677037b58e69668..f4147146261e242a62342997fda716cc263c5535:/source/posts/Fibonacci_golden_spiral.org diff --git a/source/posts/Fibonacci_golden_spiral.org b/source/posts/Fibonacci_golden_spiral.org index c4eeed8..90abf9a 100644 --- a/source/posts/Fibonacci_golden_spiral.org +++ b/source/posts/Fibonacci_golden_spiral.org @@ -1,9 +1,10 @@ #+TITLE: Creating a golden spiral in R #+AUTHOR: Frederik Vanrenterghem +#+filetags: :R:code: #+LANGUAGE: en #+PROPERTY: session *R* #+PROPERTY: cache yes -#+PROPERTY: results graphics +#+PROPERTY: results file graphics #+PROPERTY: exports both #+PROPERTY: tangle yes #+OPTIONS: toc:nil @@ -301,17 +302,17 @@ dist_from_origin <- sapply(seq_theta,polar_golden_spiral) | 46.7443082659106 | Plotting the function using coord_polar in ggplot2 does not work as intended. Unexpectedly, the x axis keeps extending instead of circling back once a full circle is reached. Turns out coord_polar might not really be intended to plot elements in polar vector format. -#+BEGIN_SRC R :session R :results output graphics :file ../pics/golden_spiral-coord_polar-fail.png :exports both +#+BEGIN_SRC R :session R :results output file graphics :file ../assets/golden_spiral-coord_polar-fail.png :exports both ggplot(data.frame(x = seq_theta, y = dist_from_origin), aes(x,y)) + geom_point() + coord_polar(theta="x") #+END_SRC #+RESULTS: -[[file:../pics/golden_spiral-coord_polar-fail.png]] +[[file:../assets/golden_spiral-coord_polar-fail.png]] To ensure what I was trying to do is possible, I employ a specialised plotfunction instead -#+BEGIN_SRC R :session R :results output graphics :file ../pics/golden_spiral-plotrix.png :exports both +#+BEGIN_SRC R :session R :results output file graphics :file ../assets/golden_spiral-plotrix.png :exports both plotrix::radial.plot(dist_from_origin, seq_theta,rp.type="s", point.col = "blue") #+END_SRC @@ -339,7 +340,7 @@ df <- data.frame(t(serie)) * Result With everything now ready in the right coordinate system, it's now only a matter of setting some options to make the output look acceptable. -#+BEGIN_SRC R :session R :results output graphics :file ../pics/golden_spiral-ggplot-coord-fixed.png :width 800 :height 800 :exports both +#+BEGIN_SRC R :session R :results output file graphics :file ../assets/golden_spiral-ggplot-coord-fixed.png :width 800 :height 800 :exports both ggplot(df, aes(x=X1,y=X2)) + geom_path(color="blue") + theme(panel.grid.minor = element_blank(),