#-- crackers data: scatterplot analysis by promotion ---
library(tidyverse)
library(xlsx)
crackers.df <- read_csv("./data/crackers.csv")
sp <- ggplot(data=crackers.df,aes(x=x.pre,y=y.post))
sp + 
  geom_point(shape=16,size=3,aes(color=promotion)) +
  theme_classic() +
  theme(text = element_text(size = 12, colour="black"),
        axis.line = element_line(
          arrow = arrow(type="closed",length = unit(8,'pt')))) + 
  scale_x_continuous(limits = c(15,36)) +
  scale_y_continuous(limits = c(20,46),breaks=seq(20,45,5)) +
  labs(x="\nCracker boxes sold before promotion\n",
       y="\nCracker boxes sold during promotion\n",
       color="Promo") +
  scale_color_manual(values = c("blue","red","purple"))
ggsave(filename="./output/salesPromo.png", 
       width = 4.5, height = 3.8,units = "in")
  
    #-- Create an Excel workbook Object
wb <- createWorkbook()
sheet <-createSheet(wb, sheetName = "scatterplot")
    # Add the scatterplot previously created to the wb
addPicture("output/salesPromo.png", sheet, scale = 1, startRow = 4,
           startColumn = 1)
    # Remove the plot from the disk if needed
res <- file.remove("output/salesPromo.png")
saveWorkbook(wb, "output/Copy scatterplot to Excel.xlsx")
