---
title: "Minimum wages trends in FBiH-Covid-19 impact"
author: "created by Amra Fetahovic for PREMISA Association"
output:
flexdashboard::flex_dashboard:
orientation: columns
social: menu
source_code: embed
---
```{r setup, include=FALSE}
library(highcharter)
library(dplyr)
library(viridisLite)
library(forecast)
library(treemap)
library(flexdashboard)
thm <-
hc_theme(
colors = c("#857781", "#BF6EA6", "#d40f3d"),
chart = list(
backgroundColor = "transparent",
style = list(fontFamily = "Source Sans Pro")
),
xAxis = list(
gridLineWidth = 0.5
)
)
```
```{r}
library(readxl)
UdruzenjePREMISA_Podaci <- read_excel("C:/Users/PC/Dropbox/Zaposlenost covid FPU/minimalne plate porezna/UdruzenjePREMISA_Podaci.xlsx", sheet="by fbih sheet 2")
mwdsbrd <- UdruzenjePREMISA_Podaci[,-c(3)]
```
```{r include=FALSE}
#transform to timematrix...
mwdsbrd
mwdsbrd.ts <- ts(mwdsbrd[,2], start = c(2019,1,1), end = c(2020,6,1), frequency = 12)
class(mwdsbrd.ts)
mwdsbrd.ts
```
Column {data-width=600}
-----------------------------------------------------------------------
### Minimum wage total
```{r}
mwdsbrd.ts %>%
hchart() %>%
hc_add_theme(thm)%>%
hc_yAxis(minorTickInterval=0) %>% hc_legend("none")
```
### Minimum wage total {.mobile}
```{r}
mwdsbrd.ts %>%
hchart() %>%
hc_add_theme(thm)%>%
hc_yAxis(minorTickInterval=0) %>% hc_legend("none")
```
### Number of Employed who received below 430BAM
```{r}
#formating the chunck
library(dplyr)
UdruzenjePREMISA_Podaci <- read_excel("UdruzenjePREMISA_Podaci.xlsx", sheet = "Sheet2")
#rename it with mw
mw <- UdruzenjePREMISA_Podaci
#rename columns
names(mw) <- c("Date", "Canton", "Municipality", "Number")
# delete non valid rows
library(dplyr)
mw <- mw %>% filter(Canton != "UKUPNO")
#make date format
mw$Date1 <- paste(mw$Date,"-01")
library(lubridate)
mw$Date1 <- ymd(mw$Date1)
#capitalize each in Municipality
library(stringr)
mw$Municipality <- str_to_title(mw$Municipality)
#display only municipality above 1,000 mw
#first sort them
library(dplyr)
mw1 <- mw %>% group_by(Municipality)
#remove BD and RS
# Find rows that match content of 2 column cell values.
mw_cantons <- mw1 %>% group_by(Canton , Date1)
mw_cantons <- mw_cantons %>% filter(Canton != "REPUBLIKA SRPSKA", Canton != "DISTRIKT BRČKO", Canton != "NA", Canton != "UKUPNO")
#Correct the strings
#capitalize each in Municipality
library(stringr)
mw_cantons$Canton <- str_to_title(mw_cantons$Canton)
#form the correct dataset
mw_cantons <- mw_cantons %>% group_by(Canton , Date1)
mw_bycantons <- mw_cantons %>% summarise(CantonSum = sum(Number, na.rm = T))
```
```{r}
#prepering the database for spageti plot
#order canton variable in Canton1 for df bycantons
mw_bycantons$Canton1 <- mw_bycantons$Canton
mw_bycantons <- as.data.frame(mw_bycantons)
mw_bycantons$Canton1 <- factor(mw_bycantons$Canton , levels = c("Zeničko-Dobojski Kanton", "Tuzlanski Kanton", "Kanton Sarajevo", "Srednjobosanski Kanton","Hercegovačko-Neretvanski Kanton","Unsko-Sanski Kanton", "Zapadno-Hercegovački Kanton","Kanton 10", "Bosanskopodrinjski Kanton","Kanton Posavski"))
##prvo formiramo objekat nayvacemoga Date_vline
Date_vline <- as.Date(c("2020-04-01")) # Define positions of vline
Date_vline <- which(mw_bycantons$Date1 %in% Date_vline)
```
```{r message=FALSE, warning=FALSE}
#calling the libraries
library(stringr)
library(viridis)
library (ggplot2)
library(plotly)
```
```{r,fig.width=100, fig.height=40}
mw_spagheti_cantons <- mw_bycantons %>% mutate(Canton2=Canton1)
plot.spagethi<-mw_spagheti_cantons %>%
ggplot(aes(x=Date1, y=CantonSum)) +
geom_line(data=mw_spagheti_cantons %>% dplyr::select(-Canton1), aes(group = Canton2), color="#857781", size=0.4, alpha=0.5) +
geom_line(aes(color=name), color="#BF6EA6", size=0.9 )+
theme(legend.position="none",
plot.title = element_text(size=10),
panel.grid = element_blank()) + theme_void()+
facet_wrap(~Canton1, nrow = 2) + scale_x_date(date_labels="%Y-%m",date_breaks ="1 month") + theme(text = element_text(size=7),strip.text = element_text(size=7), axis.text.x=element_text(angle = 90, hjust = 0, size=7),axis.text.y=element_text(size=7))+ ylab(" ") + xlab(" ") +
geom_vline(xintercept = as.numeric(mw_bycantons$Date1[Date_vline]),
col = "#d40f3d", lwd = 0.4)
ggplotly (plot.spagethi)
```
Column {.tabset data-width=400}
-----------------------------------------------------------------------
```{r}
#I want to see the difference betwean the drop in march and april by municipality
mw_canton_1mdrop <- filter(mw_cantons, Date1 == '2020-03-01'|Date1 =='2020-04-01') #I am first filtering the dates I need
mw_canton_1mdrop <- mw_canton_1mdrop %>% group_by(Municipality,Canton) %>%
summarise(drop.m = diff(Number))
#vSize prepoznaje samo plus ne minus pa cu dodati novu varijablu abs od diff(Number)
mw_canton_1mdrop$absNumber <- abs(mw_canton_1mdrop$drop.m)
#posto mw_canton_1mdrop ima 79 varijabli tj. opcina mi hocemo samo da vizualiyiramo 30 gdje je bio najveci pad
mw_canton_1mdrop.sort <- mw_canton_1mdrop %>% arrange(desc(absNumber))
mw_canton_1mdrop.top30 <- mw_canton_1mdrop.sort[1:30,]
```
### Drop by Municipality
```{r, fig.keep='none'}
tm <- treemap(mw_canton_1mdrop.top30, index = c("Municipality" ),
vSize = "absNumber", vColor = "absNumber",
type = "value", palette = rev(c("#BF6EA6", "#d40f3d","#857781")))
hctreemap(tm) %>%
hc_add_theme(thm)
```
### Drop by Cantons
```{r}
#da prikazem barplot po kantonima
mw_canton.bar <- mw_canton_1mdrop.sort %>% group_by(Canton) %>% summarise(Total.drop = sum(drop.m, na.rm = T))
mw_canton.bar$abs.Total.drop <- abs(mw_canton.bar$Total.drop)
mw_canton.bar <- mw_canton.bar %>% arrange(abs.Total.drop)
mw_canton.bar %>%
.$Canton %>%
rep(times = mw_canton.bar$abs.Total.drop) %>%
factor(levels = unique(.)) %>%
hchart(showInLegend = FALSE, name = "Employment Drop", pointWidth = 20,type = "bar") %>%
hc_add_theme(thm) %>%
hc_chart(type = "bar")
```
### Reaching the pre Covid state by Cantons
```{r}
#first transform data from long to wide
library(reshape)
library(dplyr)
mw <- as.data.frame(mw) #it works on df format
wide <- reshape(mw, v.names = "Number", idvar = c("Canton", "Municipality"),
timevar = "Date", direction = "wide", drop = "Date1")
library(htmlwidgets)
TotalG <- gauge(round(wide$`Number.2020-06`/wide$`Number.2019-03`*100,0), min = 0, max = 100, symbol = '%', gaugeSectors(success = c(80, 100), warning = c(50, 79), danger = c(0, 49)),label = "June/March Total" )
bpk.wide <- filter(wide, Canton== "BOSANSKOPODRINJSKI KANTON")
BPKG <- gauge(round(bpk.wide$`Number.2020-06`/bpk.wide$`Number.2019-03`*100,0), min = 0, max = 100, symbol = '%', gaugeSectors(success = c(80, 100), warning = c(50, 79), danger = c(0, 49)),label = "June/March BPK" )
KS.wide <- filter(wide, Canton== "KANTON SARAJEVO")
KSG <- gauge(round(KS.wide$`Number.2020-06`/KS.wide$`Number.2019-03`*100,0), min = 0, max = 100, symbol = '%', gaugeSectors(success = c(80, 100), warning = c(50, 79), danger = c(0, 49)),label = "June/March KS" )
SBK.wide <- filter(wide, Canton== "SREDNJOBOSANSKI KANTON")
SBKG <- gauge(round(SBK.wide$`Number.2020-06`/SBK.wide$`Number.2019-03`*100,0), min = 0, max = 100, symbol = '%', gaugeSectors(success = c(80, 100), warning = c(50, 79), danger = c(0, 49)),label = "June/March SBK" )
```
```{r gauge1, fig.width=2, fig.height=2}
TotalG
```
```{r gauge2, fig.width=2, fig.height=2}
BPKG
```
```{r gauge3, fig.width=2, fig.height=2}
KSG
```
```{r r gauge4, fig.width=2, fig.height=2}
SBKG
```
Sidebar {.sidebar}
======================================================================
```{r sidebar}
```
This visualization covers the data depending on the employees place of residence (so it covers only those employees that are employed at the companies registered in FBiH). Most of the data presents only residence in FBiH except one that shows RS and BDBiH.
This dashboard represents the overview of the wages that workers received since 01.2019 until 06.2020 that is below 430BAM. The data source is: Federal tax office, and it covers companies that are registered in FBiH and employees dependent on the place of residence. Of on the restrains is that the actual salary could be higher but due to some administrative bans the paid salary is lower.
Use tab __Minimum wage Total__ represents changes in FBiH (companies that are registrated in FBiH and employees that have residence in FBiH). The second graw is so-called spagheti graph that represents trends in the cantons.
The third graph on the right (heat graph) show the top 30 municipalities that experinced the largest drop in minimum wages in April respect march(when the drop was obviusly affected by the lock-down in march). the following is the barplot showing among the cantons sorted by the highest drop. The third on the right menu is represents all workers that work for FBiH companies (which means it shows data for RS and BD people working for companies in FBiH), and lastly there is gauge diagram..