library(tidyverse)
library(scales) #I use percent() function from this package 
crackers.df <- read_csv("./data/chap5/crackers-loc.csv")
crackers.df %>%
  count(location) %>%
  arrange(desc(location)) %>%
  mutate(ypos = cumsum(n)-0.5*n) -> location.df
location.df
ggplot(location.df,aes(x="", y=n, fill=location)) +
  geom_bar(stat="identity", color="white",width=1) +
  coord_polar(theta="y",start=1) +
  geom_text(aes(y=ypos, label=percent(n/sum(n))), 
            fontface="bold",color="white",size=5) +
  scale_fill_manual(values=c("red","blue","brown")) +
  theme_void()
ggsave(filename="./images/chap5/piechart2d.pdf", 
       width = 4.5,height = 3.8,units = "in")