2019-BKM- Sectoral Distribution of Expenditures

1.Introduction

I examined the data of BKM, “Sectoral Distribution of Expenditures in 6 Months in 2019”.
The web site is here: BKM-Secilen aya ait sektorel gelisim
I compiled the data in web site.Used Rvest, GGplot2 and Dplyr from Library of R.
library(rvest)
library(dplyr)
library(ggplot2)


url <- "https://bkm.com.tr/secilen-aya-ait-sektorel-gelisim/?filter_year=2019&filter_month=1"
page <- read_html(url)
table_1 <- html_table(page, fill = TRUE)[[4]][-c(1:2),]


for(i in 2:6) {
  url <- paste("https://bkm.com.tr/secilen-aya-ait-sektorel-gelisim/?filter_year=2019&filter_month=", i, sep = "")
  page <- read_html(url)
  table_1 <- bind_rows(table_1, html_table(page, fill = TRUE)[[4]][-c(1:2),-1])
}

sectr <- c(table_1 %>% select(X1) %>%  filter(X1 != "NA"))
sectr_1 <- c(rep(sectr[["X1"]], times=6))

table_2 <- table_1 %>% mutate(X1 = sectr_1) %>% filter(X1 != "TOPLAM")

month_1 <- c(rep(1:6, times=1, each=26))
table_3 <- table_2 %>% mutate(Month = month_1)
table_4  <- as.data.frame(lapply(table_3, function(x) as.numeric(gsub(",", ".", gsub("\\.", "", x)))))
## Warning in FUN(X[[i]], ...): Zorlamadan dolayı ortaya çıkan NAs
table_4 [,1] <- table_3[,1]

colnames(table_4)<-c("Sector","Numb_CC","Numb_DC","Amount_CC","Amount_DC","Months")

2. Analysis

Credit Cards and Debit Cards Average Transaction Amount

table_4<-table_4 %>% select(Sector,Numb_CC,Numb_DC,Amount_CC,Amount_DC,Months) %>% mutate(avg_amount_CC=(Amount_CC*1000000)/Numb_CC) %>% mutate(avg_amount_DC=(Amount_DC*1000000)/Numb_DC)



gg1 <- ggplot(table_4, aes(x=Sector, y=avg_amount_CC)) +
  geom_bar(stat="identity",fill="purple")+ coord_flip() + 
  labs(title = "Average Transaction Amount (Credit Card)", x="", y="") +theme_minimal() 
print(gg1)

gg2 <- ggplot(table_4, aes(x=Sector, y=avg_amount_DC)) +
  geom_bar(stat="identity",fill="purple")+ coord_flip() + 
  labs(title = "Average Transaction Amount (Debit Card)", x="", y="") +theme_minimal() 
print(gg2)

Top 5 Sector in the 6th month

top_5 <- table_4 %>% select(Sector,Numb_CC,Numb_DC,Amount_CC,Amount_DC,Months) %>%  filter(Months == 6)  %>% 
  mutate(Total_Amount=Amount_CC+Amount_DC) %>% top_n(5,Total_Amount) %>% arrange(desc(Total_Amount))

print(top_5)
##                           Sector   Numb_CC  Numb_DC Amount_CC Amount_DC
## 1 MARKET VE ALIŞVERİŞ MERKEZLERİ 105519907 63410233  12353.26   2892.63
## 2              GİYİM VE AKSESUAR  32253174 15240380   6116.57   2129.29
## 3   BENZİN VE YAKIT İSTASYONLARI  32572382 13813215   6515.69   1195.27
## 4                   ÇEŞİTLİ GIDA  31076151 20446524   5147.68    994.90
## 5              HİZMET SEKTÖRLERİ  22032853  6229279   4268.50    713.24
##   Months Total_Amount
## 1      6     15245.89
## 2      6      8245.86
## 3      6      7710.96
## 4      6      6142.58
## 5      6      4981.74
gg3<-ggplot(top_5, aes(x="", y=Total_Amount, fill=Sector)) + geom_bar(stat="identity", width=1) + coord_polar("y", start=0) +geom_text(aes(label = paste0(round(Total_Amount))), position = position_stack(vjust = 0.5))
print(gg3)