July 14, 2018

Introduction - Retail Grocery Discount Analysis

This analysis looks at the discount dollars that are given in the retail grocery industry as they relate to the total dollar sales and the total unit sales. The graphing focuses on showing the relationship between several combinations of those variables and includes access to an interactive plot, data table and basic documentation.

Shiny App Location - https://edloessi.shinyapps.io/Retail-Discount-Dollars-Analysis/

Github Location - https://github.com/edloessime/DDP-WK-Four-Retail-Discount-Analysis

Data Definitions

The following are the definitions of the key data elements used in the analysis.

  • Discount Dollars = The dollar amount of discounts provided given customer purchases
  • Sales = The dollar amount of sales of groceries for a group of transactions
  • Units = The number of individual products for a group of sales transactions

Slide with R Code

A summary report of the store data file.

storedata = read.csv("storeApplicantFile.csv")
summary(storedata)
##              city       state      storeNumber     discountDollars  
##  MANCHESTER    :  395     :  98   Min.   :  1.00   Min.   :-5027.0  
##  BANGOR        :  292   MA:1556   1st Qu.: 46.00   1st Qu.: -148.0  
##  ROCHESTER     :  198   ME:6040   Median : 91.00   Median :  -67.0  
##  SO. BURLINGTON:  198   NH:3547   Mean   : 91.06   Mean   : -145.3  
##  BEDFORD       :  197   NY:4824   3rd Qu.:136.00   3rd Qu.:  -28.0  
##  DOVER         :  197   VT:1679   Max.   :181.00   Max.   :  149.0  
##  (Other)       :16267                                               
##        date       numTransactions      sales            units      
##  1/1/2018:  181   Min.   :   1.0   Min.   : -3332   Min.   :    1  
##  1/2/2018:  181   1st Qu.:  29.0   1st Qu.:   852   1st Qu.:  293  
##  1/3/2018:  181   Median :  45.0   Median :  1587   Median :  533  
##  1/4/2018:  181   Mean   :  78.7   Mean   :  3658   Mean   : 1187  
##  1/5/2018:  181   3rd Qu.:  70.0   3rd Qu.:  2968   3rd Qu.:  985  
##  1/7/2018:  181   Max.   :1638.0   Max.   :139774   Max.   :40966  
##  (Other) :16658                                                    
##  cardedCustCount     julianDate         date.1     
##  Min.   :   1.00   Min.   :17440   1/1/2018:  181  
##  1st Qu.:  25.00   1st Qu.:17464   1/2/2018:  181  
##  Median :  38.00   Median :17489   1/3/2018:  181  
##  Mean   :  69.83   Mean   :17489   1/4/2018:  181  
##  3rd Qu.:  60.00   3rd Qu.:17513   1/5/2018:  181  
##  Max.   :1534.00   Max.   :17539   1/7/2018:  181  
##                                    (Other) :16658

Server.R code

server <- function(input, output) { storedata = reactive ({read.csv("storeApplicantFile.csv")})

# Create the scatterplot object the plotOutput function is expecting
output$scatterplot <- renderPlot({
  ggplot(data = storedata(), aes_string(x = input$x, y = input$y,
                                   color = input$z)) +
    geom_point(alpha = input$alpha)
  
})
  # Create data table
  output$storedatatable <- DT::renderDataTable({
    req(storedata())
            storedata_sample <- storedata() %>%
      sample_n(input$n)
      # select(title:store)
    DT::datatable(data = storedata_sample, 
                  options = list(pageLength = 10), 
                  rownames = FALSE)
      })
}