title: "Lab 5 Plots" author: "Ariela Kurtzer" date:
"r Sys.Date()" output: html_document ---
library(completejourney) library(tidyverse) install.packages("completejourney") library(dplyr) library(ggplot2)
dem <- demographics prod <- products trans <- transactionssample prom <- promotionssample
```{r}
library(completejourney) library(tidyverse) install.packages("completejourney") library(dplyr) library(ggplot2)
trans <- transactionssample dem <- demographics prod <- products trans <- transactionssample prom <- promotions_sample
transdem <- transactionssample %>% innerjoin(demographics, by = "householdid") %>% innerjoin(prod, by = "productid")
averagesalesbycategoryage <- transdem %>% groupby(productcategory, age) %>% summarise(averagesales = sum(salesvalue * quantity, na.rm = TRUE)) %>% filter(productcategory %in% c("BREAKFAST SWEETS", "BROCCOLI/CAULIFLOWER"))
averagesalesbycategoryage %>% ggplot(aes(x = age, y = averagesales, fill = productcategory)) + geom_bar(stat = "identity", position = "dodge") + ggtitle("Average Sales by Age for Breakfast Sweets and Broccoli/Cauliflower") + ylab("Average Sales") + xlab("Age")
{r}
promtrans <- promotionssample %>% innerjoin(transactionssample, by = "storeid") %>% mutate(totalcoup = quantity * coupondisc) %>% groupby(displaylocation) %>% summarise(couptotalspend = sum(totalcoup))
promtrans %>% ggplot(aes(x = displaylocation, y = couptotalspend)) + geombar(stat = "identity") + ggtitle("Total Coupon Discounts by Location") + scaley_continuous(breaks = seq(1000, 400000, by = 99000)) + ylab("Total Sales") + xlab("Location")
```
```{r}
promdemtrans <- transdem %>% innerjoin(prod, by = "productid") %>% filter(productcategory.y == c("SOUP", "COLD AND FLU")) %>% groupby(week, kidscount, productcategory.y) %>% summarise(totalsales = sum(sales_value))
promdemtrans %>% ggplot(aes(x = week, y = totalsales, color = productcategory.y)) + geomline(stat = "identity") + ggtitle("Cold/Flue Medicine and Soup Purchases Over Time") + scaleycontinuous(name = "Total Spend", labels = scales::dollar) + xlab("Week") + facetgrid(~ kids_count)
```