library(tidyverse)
crackers.df <- read_csv("./data/chap5/crackers-loc.csv")
by.locprom <- crackers.df %>%
  group_by(promotion,location) %>%
  summarise(mx.pre=mean(x.pre)) %>%
  ungroup()
sp <- ggplot(data=by.locprom,
             mapping=aes(x=promotion,y=mx.pre,fill=location))
dodged <- sp + 
  geom_bar(stat="identity", position="dodge")  +
  scale_fill_manual(values=c("red","forestgreen","yellow")) +
  labs(y="Average number pre-promotion sales\n") +
  theme_light()
#-- creating a vertical dodged bar chart
dodged +
  geom_text(aes(label=round(mx.pre,2)),
            position=position_dodge(width=0.9),
            fontface="bold",color="black",vjust=2)
ggsave(filename="./images/chap5/bar@vdodgedbar.pdf",
       width = 4.5, height = 3.8,units = "in")

#-- creating a horizontal dodged bar chart
dodged + 
  coord_flip() +
  geom_text(aes(label=round(mx.pre,2)),
            position=position_dodge(width=0.9),
            fontface="bold",color="black",hjust=2)
ggsave(filename="./images/chap5/bar@hdodgedbar.pdf",
       width = 5.5,height = 3.8,units = "in")