#-- crackers data: multiple line plots  ---

library(tidyverse)
crackers.df <- read_csv("./data/chap5/crackers.csv")
mylinetypes <- c("twodash","solid")
mycolors <- c("gray","black")
crackers1.df <- crackers.df %>% 
  rowwise() %>% 
  mutate(xy.mean=mean(c(x.pre,y.post)))
crackers2.df <- crackers1.df %>%
  pivot_longer(cols = c(y.post,xy.mean),
               names_to = "depvar",values_to = "sales")
sp <- ggplot(data=crackers2.df,aes(x=x.pre,y=sales))
sp + 
  geom_line(size=1,mapping = aes(linetype=depvar,color=depvar)) +
  scale_linetype_manual(values = mylinetypes) +
  scale_color_manual(values = mycolors) +
  theme_classic() +
  theme(text = element_text(size = 12, colour="black"),
        axis.line = element_line(
          arrow = arrow(type="closed",length = unit(8,'pt'))),
        legend.direction = "horizontal",
        legend.position = c(0.4,0.9)) + 
  scale_x_continuous(limits = c(15,36)) +
  scale_y_continuous(limits = c(15,52),breaks=seq(15,50,5)) +
  labs(x="\nCracker boxes sold before promotion\n",
       y="\nCracker boxes sold during promotion\n",
       linetype="Sales: ",color="Sales: ")
ggsave(filename="./images/chap5/mlineplots.pdf", width = 4.5,
       height = 3.8,units = "in")
