Happy Pi(e) Day: How To Make Pie Chart in R and Python? (but Never Make it)

Happy Pi(e) Day! Pi Day is for celebrating the mathematical constant ? (pi) and it is on March 14 (3/14). It is also Albert Einstein’s birthday!

Today is probably the only day you can think of making a Pie Chart. Pie Chart has been around for a while and notorious for eye-candy but misleading plots. Just Google “why not to use pie charts”, you will find number of reasons. Two simple reasons are that it is really hard to get the right percentage from Pie chart and there are other better ways to visualize the same data.

How To Make Pie Chart in R?

Let us make a data frame to plot Pie chart.

df <- data.frame(
  variable = c("Yet to eat", "Eaten"),
  value = c(20, 80)
)

ggplot2’s coord_polar() function will help us make pie chart.

df %>% ggplot(aes(x = "", y = value, fill = variable)) +
  geom_col(width = 2) +
  scale_fill_manual(values = c("grey", "blue")) +
  coord_polar("y", start = pi / 3) +
  labs(title = "Happy Pi(e) Day")
Pie Chart in R
How to Make Pie Chart in R?

How To Make Pie Chart in Python?

Let us make a small data frame to make Pie Chart.

df = pd.DataFrame([8,2], 
        index=['Eaten', 'To Be Eaten'], 
        columns=['x'])

With Pandas’ plotting function plot, one can specify “kind=pie” to make Pie chart using Python.

df.plot(kind='pie', subplots=True, figsize=(6, 6))
How To Make Pie chart with Pandas Python?