Intro

row


Intro
This dashboard contains spending data of one credit card from October 2018 to December 2019. 5 Questions have been addressed when analyzing the data: 1) What is the trend of spend in 2019? 2) How is spend affected by day of the week? 3) Which Category had the greatest spend in 2019? 4) What’s the top 10 restaurants? 5) What is the relationship between Travel and Shopping?

Spending Trend

row

Weekly Trend

Monthly Trend

Spend by Day of Week

row

Spend by Day of the Week

Spend by Category

row

Spend by Category

Top 10 Restaurants

row

Top 10 Restaurants

Relationship between Travel and Shopping

row

Relationship between Travel and Shopping

---
title: "ANLY 512 Final Project"
author: "Quning Chen"
date: "12/6/2019"
output:
  flexdashboard::flex_dashboard:
    orientation: columns
    vertical_layout: scroll
    source_code: embed
---

```{r setup, include=FALSE}
library(flexdashboard)
library(pdfetch)
library(dygraphs)
library(xts)
library(quantmod)
library(dplyr)
library(DT)
library(plotly)
library(lubridate)
```

Intro
====================================================================
row {}
--------------------------------------------------------------------------------------------------------

***


**Intro**  
This dashboard contains spending data of one credit card from October 2018 to December 2019. 5 Questions have been addressed when analyzing the data:
1) What is the trend of spend in 2019?
2) How is spend affected by day of the week?
3) Which Category had the greatest spend in 2019?
4) What's the top 10 restaurants?
5) What is the relationship between Travel and Shopping?


![](AmeliaGreenhallJournal.png)




Spending Trend
====================================================================
row {}
--------------------------------------------------------------------------------------------------------

### Weekly Trend

```{r}
#setwd("/Users/Ning/Documents/HU/ANLY 512 Data Visualization")
spend = read.csv("Spend.csv")
spend$Post.Date = as.Date(spend$Post.Date,"%m/%d/%y")
spend$week=floor_date(spend$Post.Date, "weeks")
spendall = aggregate(spend$Amount,list(spend$week),FUN = mean)
names(spendall) = c("week","spend")
ts_obj <- xts(spendall[ ,"spend"], order.by = spendall$week)
names(ts_obj) <- c("spend")
dts<- dygraph(ts_obj) %>% dyRangeSelector(dateWindow = c("2018-10-01", "2019-12-05"))
dts
```




### Monthly Trend

```{r}
spend2019=subset(spend,Post.Date>="2019-01-01")
spend2019$month <- strftime(spend2019$Post.Date, "%B")
spend2019$month=factor(spend2019$month,levels=month.name)
monthspend <- aggregate(spend2019$Amount, by=list(Category=spend2019$month),FUN=sum)
ggplot(monthspend, aes(x=Category, y=x)) + 
  geom_bar(stat="identity", position="identity", width=.7, colour = "goldenrod2", fill = "gold1") +
  scale_x_discrete(name = "Month", breaks = seq(0, 13, 1))+
  scale_y_continuous(name = "Amount", limits=c(-1000, 5000)) +
  ggtitle("Monthly Spend in 2019") +
  geom_text(aes(label=x), position=position_dodge(width=0.5), vjust=-0.25, size=3) +
  theme_bw()
```


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


**Conclusion**  

The top chart shows that end of 2018 saw greatest spend, while spend remained stable in 2019. I opened this credit card account in October 2018. In order to get opening rewards, I had to spend over $4000 in the first 3 months, hence the heaviest spend.

In 2019, May, July and October had largest amount of spend since I went travelling in these months.





Spend by Day of Week
====================================================================

row {}
--------------------------------------------------------------------------------------------------------

### Spend by Day of the Week

```{r}
day_of_week <- spend %>% mutate(Weekday = weekdays(Post.Date))
ggplot(day_of_week) +
aes(Weekday, Amount) +
  geom_boxplot() 
```


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


**Conclusion**  

There're a lot outliers in this chart. Wednesday is the day with least amount of spend while weekends & Monday are most active.







Spend by Category
====================================================================

row {}
--------------------------------------------------------------------------------------------------------

### Spend by Category

```{r}
p <- plot_ly(spend, labels = ~Category, values = ~abs(Amount), type = 'pie') %>%
  layout(
         xaxis = list(showgrid = FALSE, zeroline = FALSE, showticklabels = FALSE),
         yaxis = list(showgrid = FALSE, zeroline = FALSE, showticklabels = FALSE))
p

```


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


**Conclusion**  

Based on analysis of spending by category, we can see that I spent the most on Travelling (over $11K), echoing the monthly spending trend. The second heaviest spending category is Food & Drink, which makes sense since I don't cook and almost eat out every day.






Top 10 Restaurants
====================================================================

row {}
--------------------------------------------------------------------------------------------------------

### Top 10 Restaurants

```{r, echo = FALSE, message = FALSE}
res=subset(spend,Category=="Food & Drink")
res$Description=as.character(res$Description)
res$Description1= ifelse(res$Description=="CHOWBUS*ORDER"|res$Description=="CHOWBUSORDER","CHOWBUS",res$Description)
res10= res %>%
  group_by(Description1) %>%
  summarise(Amounttotal=sum(`Amount`))%>%
  top_n(n = 10, wt = Amounttotal)
p2<- ggplot(res10, aes(x = Description1, y=Amounttotal, fill=Description1)) + 
  geom_bar(stat = "identity", fill = "Blue")+
  labs(title = "Top 10 Restaurants", x = "Restaurants", y = "Amount") +
  coord_flip()
p2
```


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


**Conclusion**  

Among all the restaurants within the Food & Drink category, I spent most money on Chowbus which is a food delivery company featuring mostly Asian food in the city. Lao Sze Chuan and Minghin are popular Chinese restaurants in Chicago where I meet with my friends all the time. I also went to Starbucks, Wow Bao and Fooda a lot as they're restaurants/food services located in my company building. 






Relationship between Travel and Shopping
====================================================================

row {}
--------------------------------------------------------------------------------------------------------

### Relationship between Travel and Shopping

```{r, echo = FALSE, message = FALSE}
trashop = subset(spend,Category == "Shopping" | Category == "Travel")
ggplot(data=trashop, aes(x=Post.Date, y=abs(Amount), group=Category)) +
  geom_line(aes(color=Category))
```


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


**Conclusion**  

I examined the relationship between Travel and Shopping because I have been balancing spend on the two categories deliberably. If I go travel in one month, I wouldn't do much shopping just so that I don't go over budget. From the chart we can see that peaks occurred in different periods for the two categories with the exception of Q4 each year because of holidays and Black Friday sales.