Overview

1/ Project Objective:

Develop a visualization dashboard based on a series of credit card payment data about my spending habits from Oct 2020 to Oct 2021.

2/ Data Collection Methods:

Using my credit card company’s statements, I could collect my data. Using R (such as lubridate::floor_date function), I transformed the data sets that has unwanted rows and columns. After all, there are three data points remained: 1) Transaction Date 2) Category, and 3) Amount. Then I add one more column where it shows each month between Oct 2020 and Oct 2021.

3/ The 5 Big Questions:

  1. How often do I use my credit card each month?
  2. Which category did I spend the most?
  3. Does transactions (month-year) predict amount?
  4. Compare shopping and groceries expenses, is there any interesting pattern?
  5. How was my spending habit in each category? Any interesting relationship?

Question 1

Column

Table

Month

Question 2

Column

Chart

Question 3

Column

Date

Question 4

Column

Grocery

Shopping

Question 5

Column

Spending Habit

---
title: "ANLY 512 - Final Project"
author: "ByoungJun Jo"
output: 
  flexdashboard::flex_dashboard:
    orientation: columns
    vertical_layout: fill
    source_code: embed
---

```{r setup, include=FALSE}

library(flexdashboard)
library(DT)
library(ggplot2)
library(dplyr)
library(dygraphs)
library(tidyverse)
library(lubridate)

data <- read.csv("data.csv")
data$Transaction.Date <- as.Date(data$Transaction.Date, format="%m/%d/%y")
```

Overview
===================================== 

1/ Project Objective:

Develop a visualization dashboard based on a series of credit card payment data about my spending habits from Oct 2020 to Oct 2021.

2/ Data Collection Methods:

Using my credit card company's statements, I could collect my data. Using R (such as `lubridate::floor_date` function), I transformed the data sets that has unwanted rows and columns. After all, there are three data points remained: 1) Transaction Date	2) Category, and 3) Amount. Then I add one more column where it shows each month between Oct 2020 and Oct 2021.

3/ The 5 Big Questions:

1. How often do I use my credit card each month?
2. Which category did I spend the most?
3. Does transactions (month-year) predict amount?
4. Compare shopping and groceries expenses, is there any interesting pattern?
5. How was my spending habit in each category? Any interesting relationship?

Question 1
===================================== 

Inputs {.sidebar}
-------------------------------------

### Question 1

How often do I use my credit card each month?

Note that it's not how much I used my credit card from Oct 2020 to Oct 2021. It varies month to month but it's about 30 transactions. That means I made a credit card transaction at least one per day. 

But towards the end of 2021, I switched to a different credit card so the transaction volumen went down significantly. With the table, it is easier to navigate when and how much I spent for each transaction.

Column {.tabset}
-------------------------------------

### Table
```{r}
data %>% 
  datatable()
```    

### Month

```{r}
data$Transaction.Month.Year <- lubridate::floor_date(data$Transaction.Date, "month")

bar1 <- ggplot (data, aes(x = Transaction.Month.Year, fill = Category)) +
  geom_bar() +
  theme_bw() +
  theme(axis.text.x=element_text(angle = -45, hjust = 0)) +
  labs(title = "Credit Card Usage By Month", 
       x = "Month-Year", 
       y = "Count")
bar1
```

Question 2
===================================== 

Inputs {.sidebar}
-------------------------------------
### Question 2

Which category did I spend the most?

I spent the most money on grocery shopping. This makes sense because the period between Oct 2020 and Oct 2021 was the peak of COVID-19 pandemic. So I couldn't go out and eat at restaurants or travel abroad for a long period of time. 

Also, it's worth mentioning that because of the pandmeic, I spent more time and money while I was browsing on the web. Around this time, I also got rid of my car so the automotive cost went down significantly.
 
Column
-------------------------------------
    
### Chart
```{r}
# Basic piechart
bar2 <- ggplot(data, aes(x="Category", y = Amount, fill = Category)) +
  geom_bar(stat="identity", width=1) +
  theme_bw() +
  labs(title = "Credit Card Usage By Category", 
       x = "Cateogry")

pie <- bar2 + 
  coord_polar("y", start = 0) +
  theme(axis.text = element_blank(),
        axis.ticks = element_blank(),
        panel.grid  = element_blank())
pie

```

Question 3
===================================== 

Inputs {.sidebar}
-------------------------------------
### Question 3

Does transactions (month-year) predict amount?

As we can see from the boxplot, it is hard to say we can predict how much I would spend each month. But with the data, we can get a median (`$16.63`) and average (`$42.92`) amount for each transaction. 

From question 1, we figure out that I do 30 transactions per month. So we take the media of each transaction and multiply it by 30, we get about `$489.90`. 

If we take the average and multiply by 30, then we get about `$1,287`. That said, we may conclude the spending can be range from `$490` and `$1,300` per month. This fits with my current recurring credit card bills which is usually around `$1,000` (excluding rent payments, of course).
  
Column {.tabset}
-------------------------------------
    
### Date


```{r}
boxplot(Amount ~ Transaction.Month.Year,
        data = data,
        main="Does transactions (month-year) predict amount?",
        xlab="Month-Year",
        ylab="Amount",
        col= rgb(0.8,0.1,0.3,0.6))
```

Question 4
===================================== 

Inputs {.sidebar}
-------------------------------------
### Question 4

Compare shopping and groceries expenses, is there any interesting pattern?

Each category has somewhat different spending patterns. For groceries, it fluctuates time to time, but it rarely goes to '0'. This means I did a grocery shopping at least once a week, which is pretty accurate. Also given the pandemic lockdown, I spent much more money on groceries than usual. 

On the other hand, shopping is more interesting than my grocery spending pattern. When you take a look at the shopping chart, it looks like I didn't spend much money for a couple of months, then it spikes up (which means I spent quite a lot of money at random interval.) 

What does this mean? Grocery shopping tend to be fixed amount. Unless I have a kid, it's always only me eating the food. However, shopping is done time to time. And my needs change, and often I buy stuff for other people. So it's more complicated than grocery shopping. 

And this leads to my last question: What about others?

Column {.tabset}
-------------------------------------
    
### Grocery
```{r}
groceries <- data[data$Category == "Groceries", ]
ggplot(groceries, aes(x=Transaction.Date, y=Amount)) +
  geom_line(color="#69b3a2", size=1, alpha=0.9, linetype=1) +
  ggtitle("Groceries Spending From Oct 2020 to July 2021")
```

### Shopping
```{r}
shopping <- data[data$Category == "Shopping", ]
ggplot(shopping, aes(x=Transaction.Date, y=Amount)) +
  geom_line(color="#FF5733", size=1, alpha=0.9, linetype=1) +
  ggtitle("Shopping Spending From Oct 2020 to July 2021")
```

Question 5
===================================== 

Inputs {.sidebar}
-------------------------------------
### Question 5

How was my spending habit in each category? Any interesting relationship?

In general, fixed costs such as groceries do not show much variability compared to shopping. And it's interesting to see that I mostly spent money on either food for my stomach or food for my brain. This makes sense. Thanks to the pandemic lockdown, I focused heavily on learning online, by taking courses and attending online lectures. And for groceries, since I couldn't go out and eat like I had done, I bought bulk of everything from Trader Joe's. 

That added up to almost `1/3` of my expenses from Oct 2020 to Oct 2021. Also note that around this time, I lived with my ex-girlfriend's family. So instead of paying rent, I picked up the family's grocery bills although it was not obligatory. In the end, I didn't save as much money as I had hoped to save. But I had a great time with them over lunches and dinners. So it was money worth spent.

Column
-------------------------------------
    
### Spending Habit

```{r}
ggplot(data, aes(x = Category, y = Amount, color = Category)) +
  theme_bw() +
  geom_boxplot() +
  scale_fill_brewer(palette = 'Dark2') +
   
  theme(axis.text.x=element_text(angle = -45, hjust = 0), legend.position = 'none') +
  labs(subtitle = "How was my spending habit in each category?")
```