M Pesa Transactions

This is a descriptive time-series analysis of deposits and withdrawals made since 3/5/2019 to 3/5/2020.The data is obtained from Safaricom.co.ke statements.

library(tidyverse)
library(readxl)
library(esquisse)
dir()                              # Check items in the currect directory
## [1] "M-Pesa-Transactions-Analysis.Rmd" "M-Pesa-Transactions Analysis.Rmd"
## [3] "M-Pesa-Transactions.Rproj"        "M_Pesa.xlsx"                     
## [5] "README.md"
Data <- read_excel("M_Pesa.xlsx")  # Load data
sapply(Data, class)                # Check variable types
## $`Receipt No.`
## [1] "character"
## 
## $`Completion Time`
## [1] "POSIXct" "POSIXt" 
## 
## $Withdrawn
## [1] "numeric"
## 
## $Balance
## [1] "numeric"
Data_1 <- Data %>%                 # Data preparation
  select(`Completion Time`, Withdrawn, Balance) %>%
  gather(key = "variable", value = "value", -`Completion Time`)
Data_1$value <- abs(Data_1$value)  # Take absolute values 
head(Data_1)
## # A tibble: 6 x 3
##   `Completion Time`   variable  value
##   <dttm>              <chr>     <dbl>
## 1 2020-03-02 09:30:05 Withdrawn    28
## 2 2020-03-02 09:30:05 Withdrawn  1000
## 3 2020-02-29 21:45:01 Withdrawn    15
## 4 2020-02-29 21:45:01 Withdrawn  1000
## 5 2020-02-29 21:22:04 Withdrawn     2
## 6 2020-02-29 21:22:04 Withdrawn    50
ggplot(Data_1, aes(x = `Completion Time`, y = value)) + 
  geom_line(aes(color = variable, linetype = variable)) + 
  scale_color_manual(values = c("darkred", "steelblue"))+
  labs(title = "M-Pesa Deposits and Withdrawals Over 1 Year",
       x = "Time",
       y = "Value",
       subtitle = "Line Graph",
       caption = "Source: Safaricom.co.ke")+
  scale_y_continuous(expand = c(0, 0), limits = c(0, 20500))+
  theme(plot.title = element_text(size = 15, 
                                  hjust = 0.5, 
                                  vjust = 1,
                                  face = "bold"),
        plot.subtitle = element_text(size = 15, 
                                     hjust = 0.5,
                                     vjust = 1,
                                     face = "italic", 
                                     colour = "black"),
        axis.title = element_text(size=15,
                                  face="bold"),
        panel.grid.major = element_blank(),
        panel.grid.minor = element_blank(),
        panel.background = element_blank(),
        axis.text.x = element_text(colour = "black",
                                   size = 15,
                                   angle = 60,
                                   vjust = 0.55),
        axis.text.y = element_text(colour = "black",
                                   size = 15),
        axis.line = element_line(colour = "black",
                                 size = 1,
                                 linetype = "solid"),
        legend.title = element_text(size = 12,
                                    face = "bold",
                                    colour = "black"),
        legend.text = element_text(size = 15))