Column

Row

Member to Borrower Conversion Rate

Portfolio at Risk (PAR) by Branch

Row

Deposit vs Loan (Branch Comparison)

PAR Summary Table

---
title: "Microfinance Performance Dashboard"
output: 
  flexdashboard::flex_dashboard:
    orientation: rows
    vertical_layout: fill
    theme: flatly
    social: menu
    source_code: embed

---


```{r load-packages}
library(flexdashboard)
library(dplyr)
library(ggplot2)
library(plotly)
library(DT)
library(readr)

# Load pre-processed data
par_summary <- readRDS("par_summary.rds")
deposit_loan <- readRDS("deposit_loan.rds")
monthly_trends <- readRDS("monthly_trends.rds")
conversion_rate <- readRDS("conversion_rate.rds")

```
Column {data-height=600}
-----------------------------------------------------------------------
### Monthly Loan and Income Trends

```{r}

monthly_trends$Month_abb <- factor(month.abb[match(monthly_trends$Month, month.name)], 
                                  levels = month.abb)


p1 <- ggplot(monthly_trends, aes(x = Month, y = Total_Income, group = 1)) +
  geom_line(color = "darkgreen", size = 1.2) +
  geom_point(size = 2) +
  labs(y = "Total Income (₱)", x = "") +
  theme_minimal()

p2 <- ggplot(monthly_trends, aes(x = Month, y = Total_Borrowers, group = 1)) +
  geom_line(color = "steelblue", size = 1.2) +
  geom_point(size = 2) +
  labs(y = "Total Borrowers", x = "") +
  theme_minimal()

plotly::subplot(ggplotly(p1), ggplotly(p2), nrows = 1, shareX = TRUE) %>%
  layout(
    title = list(text = "Monthly Income and Borrowers Trend", x = 0.5),
    xaxis = list(title = "Month"),
    xaxis2 = list(title = "Month")
  )


```
Row {data-height=600}
-----------------------------------------------------------------------
### Member to Borrower Conversion Rate {.column}

```{r}
plot_ly(
  data = conversion_rate,
  x = ~Month,
  y = ~Conversion_Rate,
  type = "scatter",
  mode = "lines+markers",
  line = list(color = "orange"),
  marker = list(size = 6)
) %>%
  layout(title = "Conversion Rate: Members to Borrowers (%)",
         yaxis = list(title = "Conversion Rate (%)",
                      ticksuffix = "%"),
         xaxis = list(title = "Month"))

```
### Portfolio at Risk (PAR) by Branch {.column}

```{r}
plot_ly(
  par_summary, 
  x = ~Month, 
  y = ~PAR_Rate, 
  color = ~Branch_name,
  type = "scatter", 
  mode = "lines+markers"
) |>
  layout(
    title = "PAR Rate by Branch Over Time",
    xaxis = list(title = "Month"),
    yaxis = list(title = "PAR Rate (%)", range = c(0, max(par_summary$PAR_Rate, na.rm = TRUE) + 5))
  )

```
Row {data-height=600}
-----------------------------------------------------------------------
### Deposit vs Loan (Branch Comparison) {.column}

```{r}
plot_ly(
  deposit_loan,
  x = ~Total_Deposit,
  y = ~Total_Loan,
  type = "scatter",
  mode = "markers",
  text = ~paste("Branch:", Branch_name),
  marker = list(size = 10, color = "navy", opacity = 0.6)
) |>
  layout(
    title = "Deposit vs Loan by Branch",
    xaxis = list(title = "Total Deposit (₱)"),
    yaxis = list(title = "Total Loan (₱)")
  )

```
### PAR Summary Table {.column}

```{r}
datatable(
  par_summary, 
  options = list(pageLength = 10),
)

```