#install.packages("lubridate")
library(tidyverse)
## Warning: replacing previous import 'lifecycle::last_warnings' by
## 'rlang::last_warnings' when loading 'tibble'
## Warning: replacing previous import 'ellipsis::check_dots_unnamed' by
## 'rlang::check_dots_unnamed' when loading 'tibble'
## Warning: replacing previous import 'ellipsis::check_dots_used' by
## 'rlang::check_dots_used' when loading 'tibble'
## Warning: replacing previous import 'ellipsis::check_dots_empty' by
## 'rlang::check_dots_empty' when loading 'tibble'
## Warning: replacing previous import 'lifecycle::last_warnings' by
## 'rlang::last_warnings' when loading 'pillar'
## Warning: replacing previous import 'ellipsis::check_dots_unnamed' by
## 'rlang::check_dots_unnamed' when loading 'pillar'
## Warning: replacing previous import 'ellipsis::check_dots_used' by
## 'rlang::check_dots_used' when loading 'pillar'
## Warning: replacing previous import 'ellipsis::check_dots_empty' by
## 'rlang::check_dots_empty' when loading 'pillar'
## ── Attaching packages ─────────────────────────────────────── tidyverse 1.3.0 ──
## ✓ ggplot2 3.3.2     ✓ purrr   0.3.4
## ✓ tibble  3.0.4     ✓ dplyr   1.0.2
## ✓ tidyr   1.1.2     ✓ stringr 1.4.0
## ✓ readr   1.4.0     ✓ forcats 0.5.0
## ── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
## x dplyr::filter() masks stats::filter()
## x dplyr::lag()    masks stats::lag()
library(readxl)
library(lubridate)
## 
## Attaching package: 'lubridate'
## The following objects are masked from 'package:base':
## 
##     date, intersect, setdiff, union
library(glue)
## 
## Attaching package: 'glue'
## The following object is masked from 'package:dplyr':
## 
##     collapse
library(readr)
cleanedtreesdf2 <- read_csv("cleanedtreesdf2.csv")
## Warning: Missing column names filled in: 'X1' [1]
## 
## ── Column specification ────────────────────────────────────────────────────────
## cols(
##   X1 = col_double(),
##   Type = col_character(),
##   Date = col_character(),
##   Num = col_character(),
##   Ship_To_Address2 = col_character(),
##   Ship_Zip = col_character(),
##   Item = col_character(),
##   Qty = col_double(),
##   Sales_Price = col_character(),
##   Amount = col_double()
## )
treedata <- cleanedtreesdf2
#View(treedata)
numdates <- treedata %>%
  mutate(Date = mdy(Date)) 
numdates
## # A tibble: 22,102 x 10
##       X1 Type  Date       Num   Ship_To_Address2 Ship_Zip Item    Qty
##    <dbl> <chr> <date>     <chr> <chr>            <chr>    <chr> <dbl>
##  1     1 Invo… 2023-07-29 9845  MacTavish Court  46703    "Tre…     2
##  2     2 Invo… 2023-07-29 9845  MacTavish Court  46703    "Tri…     1
##  3     3 Invo… 2023-05-11 SI-1… McDarmid Ave     46703    "Tre…     4
##  4     4 Invo… 2023-05-11 SI-1… McDarmid Ave     46703    "Rep…    NA
##  5     5 Invo… 2023-07-11 SI-1… McDarmid Ave     46703    "Tre…     1
##  6     6 Invo… 2023-07-11 SI-1… McDarmid Ave     46703    "Rep…    NA
##  7     7 Invo… 2023-04-12 7662R Menza Drive      46706    "Tre…     1
##  8     8 Invo… 2023-04-12 7662R Menza Drive      46706    "Rep…    NA
##  9     9 Invo… 2023-05-19 8378R Cascina Lane     46706    "Tre…     1
## 10    10 Invo… 2023-05-19 8378R Cascina Lane     46706    "Rep…    NA
## # … with 22,092 more rows, and 2 more variables: Sales_Price <chr>,
## #   Amount <dbl>
repdisc <- numdates %>%
  group_by(Item) %>%
    filter(Item == "Replacement Discount")
#view(repdisc)
numdates %>%
  ggplot(aes(x = Date, y = Amount, group =1)) +
  geom_line() + labs(title = "Money Made per Year", x = "Year", y = "Amount of Money ($)")

Amount made by year -Huge peak right before 2018

repcounted <- repdisc %>%
  count(Date) %>%
  arrange(desc(n))
repcounted
## # A tibble: 652 x 3
## # Groups:   Item [1]
##    Item                 Date           n
##    <chr>                <date>     <int>
##  1 Replacement Discount 2021-05-05     9
##  2 Replacement Discount 2021-04-15     8
##  3 Replacement Discount 2021-07-29     8
##  4 Replacement Discount 2019-06-04     6
##  5 Replacement Discount 2021-04-23     6
##  6 Replacement Discount 2022-03-23     6
##  7 Replacement Discount 2016-04-29     5
##  8 Replacement Discount 2016-05-12     5
##  9 Replacement Discount 2017-05-11     5
## 10 Replacement Discount 2019-07-23     5
## # … with 642 more rows
repcounted %>%
  ggplot(aes(x = Date, y = n, group =1)) +
  geom_line() + labs(title = "Number of Replacement Discounts Issued by Year", x = "Year", y = "Replacement Discount")

repcomonth <- repcounted %>%
  group_by(month(Date)) %>%
    count(month(Date))
#view(repcomonth)

repcomonth %>%
  ggplot(aes(x = `month(Date)`, y = n, group = 1)) + geom_line() + labs(title = "Replacement Discounts Issued by Month", x = "Month (Numeric)", y = "Replacement Discounts")

monthlysales <- numdates %>%
  group_by(month(Date)) %>%
    count(month(Date))
#view(monthlysales)

monthlysales %>%
  ggplot(aes(x = `month(Date)`, y = n)) + geom_line() + labs(title = "Sales per Month", x = "Month(Numeric)", y = "Number of Sales")