Org-Mode Piechart in a Hurry (3D!)

I needed a pie chart, and had very little time. R and Org-mode to the rescue.

I started on stackoverflow. However, I wanted a slightly more pronounced image. To save others time, here is how you add plotrix.

The result:

colourful 3D pie chart
A colourful pie chart. (source)

First, make sure you have plotrix.

apt install r-cran-plotrix
	#+TBLNAME:foo
	| population in % | continent         |
	|-----------------+-------------------|
	|            59.5 | Asia              |
	|            17.2 | Africa            |
	|             9.6 | Europe            |
	|             7.6 | North America     |
	|             5.5 | South America     |
	|            0.55 | Australia/Oceania |
	|          0.0001 | Antartica         |

	(source: https://www.worldometers.info/geography/7-continents/)


	#+name: name-of-result-block-in-org-file
	#+begin_src R :results file graphics :file foo.jpg  :var foo=foo :width 600
	library(plotrix)
	pie3D(foo[,1],labels=foo[,2],explode = 0.1, main = "Where people live")
	#+end_src

You generate the image with C-c C-c anywhere. That will add a few lines

	#+RESULTS: name-of-result-block-in-org-file
	[[file:foo.jpg]]

More information

You can read more about Org-mode and R here:

https://orgmode.org/worg/org-tutorials/org-R/org-R.html