Finance Tracker Dashboard in Data Analysis Using R

Managing personal finances is essential for maintaining financial health and achieving financial goals. Building a personal finance tracker dashboard in R can provide valuable insights into income, expenses, savings, and investment performance. In this article, we’ll outline the steps to create a simple yet effective personal finance tracker dashboard using R and popular visualization libraries like ggplot2 and shiny.

Step 1: Data Collection and Preparation

Start by gathering your financial data from sources such as bank statements, credit card statements, investment accounts, and budgeting apps. Organize the data into a structured format, such as a CSV file, with columns for date, category, amount, and description.

DataSet Link: Personal Finance

Step 2. Data Analysis and Visualization

Use R and ggplot2 to analyze and visualize your financial data. Create visualizations such as:

Creating dashboard templet

We are using R studio, so the first thing we have to do as follows:

Go to File --> New file --> R markdown --> Templet --> Flex Dashboard --> Click ok

Personal Finance Tracker Dashboard

After clicking on that we get this window.

Personal Finance Tracker Dashboard

Then you get a templet look like as follows:

Personal Finance Tracker Dashboard

Dashboard layout

Now we will create the Dashboard layout and pass the arguments in a cunks.

1. YAML (Header Defines):


---
title: "Personal Finance"
output:
flexdashboard::flex_dashboard:
orientation: rows
vertical_layout: fill
social: [ "twitter", "facebook", "menu"]
---

This section describes the dashboard’s title and layout choices. The dashboard will have social sharing buttons and rows as its main layout style.

2. Setup Chunk:

```{r setup, include=FALSE}
library(flexdashboard)
library(tidyverse)
library(highcharter)
library(gt)
library(DT)
library(htmltools)
library(plotly)
library(ggplot2)
library(plyr)
library(rpivotTable)
```
```{r}
# Import data
library(readxl)
df = read_excel("C:/Users/user/Downloads/personal finance data.xlsx")
```

The dashboard is divided into rows and columns, each of containing tables or different visuals.

3. First-row Creating value box and gauge chart:

The ### **Salary per Month** represent bold title of the column. 
### **Salary per Month**
```{r}
df_salary = df %>%
select(Category,`Debit.Credit`) %>%
filter(tolower(Category) == "salary")
gauge(round(mean(df_salary$`Debit/Credit`),
digits = 2),
min = 0,
max = 100000,
gaugeSectors(colors = "yellow"))
```

Output:

Personal Finance Tracker Dashboard

This section computes the mean salary by filtering the data for salary portions. The average monthly salary is shown visually on a gauge chart.

4. Create plots using ggplot2 and make them interactive with Plotly

Combining the power of ggplot2 for static visualizations with the interactivity of Plotly creates dynamic and engaging plots that enhance data exploration and presentation.

### **Most Frequently Spending On A Category**

```{r}
df_ = df %>%
select(Category,`Income/Expense`,`Debit/Credit`) %>%
filter(tolower(`Income/Expense`) != "income")
df_$Category = tolower(df_$Category)
bar = ggplot(data= df_)+
geom_bar(aes(x = Category, fill = Category))+
guides(fill = F)
ggplotly(bar)

```

Output:

Personal Finance Tracker Dashboard

5. The last row consists of the value box

Certainly! Let’s create a simple example of a value box using plotly in R.

1. Maximum spending

### Maximum Expense

```{r}
df_date = df %>%
select(`Date / Time`, Category,`Income/Expense`,`Debit/Credit`) %>%
mutate(`Date / Time` = as.Date(`Date / Time`)) %>%
filter(tolower(`Income/Expense`) != "income")

df_date$Category = tolower(df_date$Category)
valueBox(max(df_date$`Debit/Credit`),
icon = "fa-user" )
```

2. Average spending

### Average Expense

```{r}
df_date = df %>%
select(`Date / Time`, Category,`Income/Expense`,`Debit/Credit`) %>%
mutate(`Date / Time` = as.Date(`Date / Time`)) %>%
filter(tolower(`Income/Expense`) != "income")

df_date$Category = tolower(df_date$Category)
valueBox(round(mean(df_date$`Debit/Credit`),2),
icon = "fa-user" )

```

3. Minimum spending

### Minimum Expense

```{r}
df_date = df %>%
select(`Date / Time`, Category,`Income/Expense`,`Debit/Credit`) %>%
mutate(`Date / Time` = as.Date(`Date / Time`)) %>%
filter(tolower(`Income/Expense`) != "income")

df_date$Category = tolower(df_date$Category)
valueBox(min(df_date$`Debit/Credit`),
icon = "fa-user" )
```

6. Create a new page for the pivot table

Applies PivotTable to create a pivot table to summarize the spending of a person by category.

Table Spendimg In Each Category
==========================================================

```{r}
df_11 = df %>%
select(`Date / Time`, Category,`Income/Expense`,`Debit/Credit`) %>%
mutate(`Date / Time` = as.Date(`Date / Time`)) %>%
filter(tolower(`Income/Expense`) != "income")

df_11$Category = tolower(df_11$Category)

rpivotTable(df_11,
aggregatorName = "sum",
cols= "`Debit/Credit`",
rows = "Category" ,
rendererName = "Table Barchart")
```

Output:

Personal Finance Tracker Dashboard

There are lots of options you can use in the pivot table.

7. Data Table

Create a new page and using ‘DT::datatable’ to display the data in an interactive table in the new page.


Data Table
=============================================================

```{r}
datatable(df,
caption = "Personal Finance Data",
rownames = T,
filter = "top",
options = list(pageLength = 25))
```

Output:

Personal Finance Tracker Dashboard

It will show the complete visualization in the R Dashboard.

Here is the whole code for the process of creating the Personal Finance Tracker Dashboard.

R
---
title: "Personal Finance"
output: 
  flexdashboard::flex_dashboard:
    orientation: rows
    vertical_layout: fill
    social: [ "twitter", "facebook", "menu"]
---

```{r setup, include=FALSE}
library(flexdashboard)
library(tidyverse)
library(highcharter)
library(gt)
library(DT)
library(htmltools)
library(plotly)
library(ggplot2)
library(plyr)
library(rpivotTable)
```


```{r}
# Import data
library(readxl)
df = read_csv("C:\\Users\\GFG19565\\Downloads\\personal finance data.xlsx - Sheet1.csv")
```

Personal Finance
=======================================================================

Column
-----------------------------------------------------------------------

### **Salary per Month**
```{r}
df_salary = df %>%
  select(Category,`Debit/Credit`) %>%
  filter(tolower(Category) == "salary")
gauge(round(mean(df_salary$`Debit/Credit`),
            digits = 2),
      min = 0,
      max = 100000,
      gaugeSectors(colors = "yellow"))
```

### Total Allowences Get

```{r}
df_all = df %>%
  select(Category,`Debit/Credit`) %>%
  filter(tolower(Category) == "allowance")

valueBox(sum(df_all$`Debit.Credit`),
         icon = "fa-building")
```

### Others Income

```{r}
df_other = df %>%
  select(Category,`Income/Expense`,`Debit/Credit`) %>%
  filter(tolower(Category) == "other") %>%
  filter(tolower(`Income/Expense`) == "income")

valueBox(sum(df_other$`Debit/Credit`),
         icon = "fa-building")

```

### Total Spending

```{r}
df_ = df %>%
  select(Category,`Income/Expense`,`Debit/Credit`) %>%
  filter(tolower(`Income/Expense`) != "income")
valueBox(sum(df_$`Debit/Credit`),
         icon = "fa-building")
```

### Total Savings

```{r}
df_ = df %>%
  select(Category,`Income/Expense`,`Debit/Credit`) %>%
  filter(tolower(`Income/Expense`) != "income")
df_salary = df %>%
  select(Category,`Income/Expense`,`Debit/Credit`) %>%
  filter(tolower(`Income/Expense`) == "income")
valueBox(sum(df_salary$`Debit/Credit`) - sum(df_$`Debit/Credit`),
         icon = "fa-building")
```


Row
-----------------------------------------------------------

### **Most Frequently Spending On A Category**

```{r}
df_ = df %>%
  select(Category,`Income/Expense`,`Debit/Credit`) %>%
  filter(tolower(`Income/Expense`) != "income")
df_$Category = tolower(df_$Category)
bar = ggplot(data= df_)+
  geom_bar(aes(x = Category, fill = Category))+
  guides(fill = F)
ggplotly(bar)

```

### **Monthly Spending On Each Category**

```{r}
df_date = df %>%
  select(`Date / Time`, Category,`Income/Expense`,`Debit/Credit`) %>%
  mutate(`Date / Time` = as.Date(`Date / Time`)) %>%
  filter(tolower(`Income/Expense`) != "income")

df_date$Category = tolower(df_date$Category)

l1 = ggplot(df_date, aes(x = `Date / Time`, y = `Debit/Credit`, color = Category)) +
  geom_line() +
  labs(x = "Date",
       y = "Debit/Credit",
       color = "Category")
ggplotly(l1)

```

Row
-----------------------------------------------------------------------

### Maximum Expense

```{r}
df_date = df %>%
  select(`Date / Time`, Category,`Income/Expense`,`Debit/Credit`) %>%
  mutate(`Date / Time` = as.Date(`Date / Time`)) %>%
  filter(tolower(`Income/Expense`) != "income")

df_date$Category = tolower(df_date$Category)
valueBox(max(df_date$`Debit/Credit`),
         icon = "fa-user" )
```

### Average Expense

```{r}
df_date = df %>%
  select(`Date / Time`, Category,`Income/Expense`,`Debit/Credit`) %>%
  mutate(`Date / Time` = as.Date(`Date / Time`)) %>%
  filter(tolower(`Income/Expense`) != "income")

df_date$Category = tolower(df_date$Category)
valueBox(round(mean(df_date$`Debit/Credit`),2),
         icon = "fa-user" )

```

### Minimum Expense

```{r}
df_date = df %>%
  select(`Date / Time`, Category,`Income/Expense`,`Debit/Credit`) %>%
  mutate(`Date / Time` = as.Date(`Date / Time`)) %>%
  filter(tolower(`Income/Expense`) != "income")

df_date$Category = tolower(df_date$Category)
valueBox(min(df_date$`Debit/Credit`),
         icon = "fa-user" )
```



Table Spendimg In Each Category
==========================================================

```{r}
df_11 = df %>%
  select(`Date / Time`, Category,`Income/Expense`,`Debit/Credit`) %>%
  mutate(`Date / Time` = as.Date(`Date / Time`)) %>%
  filter(tolower(`Income/Expense`) != "income")

df_11$Category = tolower(df_11$Category)

rpivotTable(df_11,
            aggregatorName = "sum",
            cols= "`Debit/Credit`",
            rows = "Category" ,
            rendererName = "Table Barchart")

```

Data Table
=============================================================

```{r}
datatable(df,
          caption = "Personal Finance Data",
          rownames = T,
          filter = "top",
          options = list(pageLength = 25))
```

Output:

Dash Board Page:1


After knitting the current file we get the below output and you can then publish your dash board on the web.

Dash Board Page:2

After knitting the current file we get the below output and you can then publish your dash board on the web.

Dash Board Page:3

Overall, this flex dashboard provides a comprehensive overview of personal finance data, allowing users to analyze income, expenses, savings, and spending patterns effectively. It offers a combination of visualizations and summary statistics for better understanding and decision-making regarding personal finances.



Contact Us