Marketing Facts of Orange Juice in Five Stores

Data Set

Sales data of two brands orange juice (CH and MM) from five retail >stores.

  • Data size: Small
  • Tuples(rows): 1070
  • Observations(records): 8560
  • Raw data format: csv

Analysis Tool

  • R (libraries: dplyr, ggplot, reshape)

Questions

1. Which store likes to give discount?

Store0 loves give discounts to both brands of orange juice. Store0, 1, 2 provide more discounts on orange juice of MM, and the store3 and 4 provide more discounts on orange juice CH.

Discounts by numbers

2. What’s highest and lowest price after discount of each brand in each store?

The cheapest CH juice was in store 1, the most expensive MM juice was in store 3 and 4.

Final price for each brand in each store

Code

# Clear environment of variables and functions
rm(list = ls(all = TRUE)) 

# Clear environmet of packages
if(is.null(sessionInfo()$otherPkgs) == FALSE)lapply(paste("package:", names(sessionInfo()$otherPkgs), sep=""), detach, character.only = TRUE, unload = TRUE)

library(tidyverse)
library(reshape2)

df_oj <- read_csv("D3_OJ_In_Class_Data.csv")
df_oj <- select(df_oj,-1)

df_oj$Purchase <- as.factor(df_oj$Purchase)
df_oj$STORE <- as.factor(df_oj$STORE)

df_oj %>% 
  group_by(STORE) %>% 
  summarise(MM = sum(DiscMM != 0), CH = sum(DiscCH != 0)) %>% 
  melt(id = "STORE") %>% 
  ggplot(aes(x = STORE, y = value, fill = variable)) + geom_col(position = "dodge") + ylab("Discount Counts for OJ") + theme(legend.title=element_blank())

df2 <- df_oj %>% 
  mutate(final_price_CH = PriceCH*(1-DiscCH)) %>% 
  group_by(STORE, Purchase) %>% 
  distinct(final_price_CH) %>% 
  top_n(1,wt = final_price_CH) %>% 
  filter(Purchase == "CH") %>% 
  melt(id = c("STORE","Purchase"))

df3  <- df_oj %>% 
  mutate(final_price_MM = PriceMM*(1-DiscMM)) %>% 
  group_by(STORE, Purchase) %>% 
  distinct(final_price_MM) %>% 
  top_n(1,wt = final_price_MM) %>% 
  filter(Purchase == "MM") %>% 
  melt(id = c("STORE","Purchase"))

df <-  full_join(df2,df3) 
df %>% 
  ggplot(aes(x = STORE, y = value, color = Purchase)) + geom_point() + ylab("Highest Price") + geom_text(aes(label = value), size = 3, hjust = -0.5)

rm("df","df2","df3")

发表评论

Fill in your details below or click an icon to log in:

WordPress.com 徽标

You are commenting using your WordPress.com account. Log Out /  更改 )

Google photo

You are commenting using your Google account. Log Out /  更改 )

Twitter picture

You are commenting using your Twitter account. Log Out /  更改 )

Facebook photo

You are commenting using your Facebook account. Log Out /  更改 )

Connecting to %s