12/6/2020

Abstract

Pharmacies typically engage with a single pharmaceutical distributor to purchase all the drugs they need. This type of arrangement is governed by a contract called a Prime Vendor Agreement (PVA), which the pharmacy enters into with the distributor for a specific number of years defined in the agreement itself. The PVA also stipulates what percentage of its drugs a pharmacy must buy from the distributor in order to be compliant with the agreement. A pharmacy may choose to purchase drugs from a distributor other than the one it has a PVA with; this is referred to as “leakage,” and it can sometimes be significant. Your challenge is to determine which drugs are being bought outside the PVA from other distributors, hypothesize why this is happening, and recommend where AmerisourceBergen should concentrate efforts to reduce this leakage and regain lost revenue and profit

Task 0: Loading libraries

knitr::opts_chunk$set(echo = TRUE)
library(readxl)
library(tidyverse)
## -- Attaching packages ------------------------------------------------------- tidyverse 1.3.0 --
## v ggplot2 3.3.2     v purrr   0.3.4
## v tibble  3.0.3     v dplyr   1.0.1
## v tidyr   1.1.1     v stringr 1.4.0
## v readr   1.3.1     v forcats 0.5.0
## -- Conflicts ---------------------------------------------------------- tidyverse_conflicts() --
## x dplyr::filter() masks stats::filter()
## x dplyr::lag()    masks stats::lag()

Task 1: Loading data

DSPN <- read_excel("C:/Users/tahma/Desktop/DSPN.xlsx")
d1 <- DSPN
head(d1)
## # A tibble: 6 x 43
##   WK_NBR WK_BEGIN_DTE WK_END_DTE NCPDP_TOKEN PHRMCY_NAME BUY_GRP_NAM NDC  
##   <chr>  <chr>        <chr>      <chr>       <chr>       <chr>       <chr>
## 1 201836 2018-09-02   2018-09-08 4410677998~ PHARMACY 1~ SPURS       0007~
## 2 201836 2018-09-02   2018-09-08 4410677998~ PHARMACY 1~ SPURS       0017~
## 3 201836 2018-09-02   2018-09-08 4410677998~ PHARMACY 1~ SPURS       1249~
## 4 201836 2018-09-02   2018-09-08 4410677998~ PHARMACY 1~ SPURS       0000~
## 5 201836 2018-09-02   2018-09-08 4410677998~ PHARMACY 1~ SPURS       0040~
## 6 201836 2018-09-02   2018-09-08 4410677998~ PHARMACY 1~ SPURS       0059~
## # ... with 36 more variables: NDC_DESC <chr>, BRX_GRX_CD <chr>,
## #   NDC_QTY_MTRC <dbl>, NDC_PKG_SZ <dbl>, NDC_CASE_PK_QTY <dbl>, MFG_NAM <chr>,
## #   GCNSEQ_NBR <chr>, GCNSEQ_DESC <chr>, GCNSEQ_RTE_OF_ADMIN_DESC <chr>,
## #   GCNSEQ_DSG_FORM_CD <chr>, GCNSEQ_STR_DESC <chr>, DSPN_QTY_NDC_1WK <dbl>,
## #   DSPN_QTY_NDC_4WKS <dbl>, DSPN_QTY_NDC_13WKS <dbl>,
## #   DSPN_QTY_NDC_26WKS <dbl>, DSPN_QTY_GCN_1WK <dbl>, DSPN_QTY_GCN_4WKS <dbl>,
## #   DSPN_QTY_GCN_13WKS <dbl>, DSPN_QTY_GCN_26WKS <dbl>,
## #   PURCH_QTY_NDC_1WK_MTRC <dbl>, PURCH_QTY_NDC_4WKS_MTRC <dbl>,
## #   PURCH_QTY_NDC_13WKS_MTRC <dbl>, PURCH_QTY_NDC_26WKS_MTRC <dbl>,
## #   PURCH_QTY_GCN_1WK_MTRC <dbl>, PURCH_QTY_GCN_4WKS_MTRC <dbl>,
## #   PURCH_QTY_GCN_13WKS_MTRC <dbl>, PURCH_QTY_GCN_26WKS_MTRC <dbl>,
## #   COGS_PRC_MTRC <dbl>, DSPN_COGS_NDC_1WK <dbl>, DSPN_COGS_NDC_4WKS <dbl>,
## #   DSPN_COGS_NDC_13WKS <dbl>, DSPN_COGS_NDC_26WKS <dbl>,
## #   DSPN_COGS_GCN_1WK <dbl>, DSPN_COGS_GCN_4WKS <dbl>,
## #   DSPN_COGS_GCN_13WKS <dbl>, DSPN_COGS_GCN_26WKS <dbl>

Task 2: Determining Mean of Drug Prices

d2 <- d1 %>% 
  group_by(NDC_DESC) %>% 
  summarise(
    mean_cogs = mean(COGS_PRC_MTRC , na.rm = T)
    ) %>% ungroup()
## `summarise()` ungrouping output (override with `.groups` argument)
print(d2)
## # A tibble: 74 x 2
##    NDC_DESC                           mean_cogs
##    <chr>                                  <dbl>
##  1 "\"ADVATE 1,801-2,400 UNIT VIAL\""    791.  
##  2 "\"ADVATE 801-1,200 UNIT VIAL\""        1.55
##  3 "\"ADYNOVATE 1,500 UNIT VIAL\""      2447.  
##  4 "\"HELIXATE FS 1,000 UNIT VIAL\""     968.  
##  5 "\"HELIXATE FS 2,000 UNIT VIAL\""       1.44
##  6 "\"KOGENATE FS 1,000 UNITS VIAL\""      1.55
##  7 "\"KOGENATE FS 2,000 UNIT VIAL\""     110.  
##  8 "\"KOVALTRY 2,000 UNIT KIT\""           1.47
##  9 "ADMELOG 100 UNIT/ML VIAL"             22.6 
## 10 "ADMELOG SOLOSTAR 100 UNIT/ML"         29.1 
## # ... with 64 more rows

Task 3 and 4: Cleaning Data

NA in COGS_PRC_MTRC is replaced with the mean of COGS_PRC and data is joined with the original data.

d3 <- inner_join(d1, d2, by = 'NDC_DESC') %>% 
  mutate(
    COGS_PRC_MTRC = ifelse(is.na(COGS_PRC_MTRC) == T, 
                           mean_cogs, COGS_PRC_MTRC)
    )

head(d3)
## # A tibble: 6 x 44
##   WK_NBR WK_BEGIN_DTE WK_END_DTE NCPDP_TOKEN PHRMCY_NAME BUY_GRP_NAM NDC  
##   <chr>  <chr>        <chr>      <chr>       <chr>       <chr>       <chr>
## 1 201836 2018-09-02   2018-09-08 4410677998~ PHARMACY 1~ SPURS       0007~
## 2 201836 2018-09-02   2018-09-08 4410677998~ PHARMACY 1~ SPURS       0017~
## 3 201836 2018-09-02   2018-09-08 4410677998~ PHARMACY 1~ SPURS       1249~
## 4 201836 2018-09-02   2018-09-08 4410677998~ PHARMACY 1~ SPURS       0000~
## 5 201836 2018-09-02   2018-09-08 4410677998~ PHARMACY 1~ SPURS       0040~
## 6 201836 2018-09-02   2018-09-08 4410677998~ PHARMACY 1~ SPURS       0059~
## # ... with 37 more variables: NDC_DESC <chr>, BRX_GRX_CD <chr>,
## #   NDC_QTY_MTRC <dbl>, NDC_PKG_SZ <dbl>, NDC_CASE_PK_QTY <dbl>, MFG_NAM <chr>,
## #   GCNSEQ_NBR <chr>, GCNSEQ_DESC <chr>, GCNSEQ_RTE_OF_ADMIN_DESC <chr>,
## #   GCNSEQ_DSG_FORM_CD <chr>, GCNSEQ_STR_DESC <chr>, DSPN_QTY_NDC_1WK <dbl>,
## #   DSPN_QTY_NDC_4WKS <dbl>, DSPN_QTY_NDC_13WKS <dbl>,
## #   DSPN_QTY_NDC_26WKS <dbl>, DSPN_QTY_GCN_1WK <dbl>, DSPN_QTY_GCN_4WKS <dbl>,
## #   DSPN_QTY_GCN_13WKS <dbl>, DSPN_QTY_GCN_26WKS <dbl>,
## #   PURCH_QTY_NDC_1WK_MTRC <dbl>, PURCH_QTY_NDC_4WKS_MTRC <dbl>,
## #   PURCH_QTY_NDC_13WKS_MTRC <dbl>, PURCH_QTY_NDC_26WKS_MTRC <dbl>,
## #   PURCH_QTY_GCN_1WK_MTRC <dbl>, PURCH_QTY_GCN_4WKS_MTRC <dbl>,
## #   PURCH_QTY_GCN_13WKS_MTRC <dbl>, PURCH_QTY_GCN_26WKS_MTRC <dbl>,
## #   COGS_PRC_MTRC <dbl>, DSPN_COGS_NDC_1WK <dbl>, DSPN_COGS_NDC_4WKS <dbl>,
## #   DSPN_COGS_NDC_13WKS <dbl>, DSPN_COGS_NDC_26WKS <dbl>,
## #   DSPN_COGS_GCN_1WK <dbl>, DSPN_COGS_GCN_4WKS <dbl>,
## #   DSPN_COGS_GCN_13WKS <dbl>, DSPN_COGS_GCN_26WKS <dbl>, mean_cogs <dbl>

Task 5: Determining Business logic

Purchase quantity should not be negative, as the negative value signifies the return from customers.

d4 <- d3 %>%
  filter(PURCH_QTY_NDC_1WK_MTRC>=0, 
         PURCH_QTY_NDC_4WKS_MTRC>=0, 
         PURCH_QTY_NDC_13WKS_MTRC>=0, 
         PURCH_QTY_NDC_26WKS_MTRC>=0)
head(d4)
## # A tibble: 6 x 44
##   WK_NBR WK_BEGIN_DTE WK_END_DTE NCPDP_TOKEN PHRMCY_NAME BUY_GRP_NAM NDC  
##   <chr>  <chr>        <chr>      <chr>       <chr>       <chr>       <chr>
## 1 201836 2018-09-02   2018-09-08 4410677998~ PHARMACY 1~ SPURS       0007~
## 2 201836 2018-09-02   2018-09-08 4410677998~ PHARMACY 1~ SPURS       0017~
## 3 201836 2018-09-02   2018-09-08 4410677998~ PHARMACY 1~ SPURS       1249~
## 4 201836 2018-09-02   2018-09-08 4410677998~ PHARMACY 1~ SPURS       0000~
## 5 201836 2018-09-02   2018-09-08 4410677998~ PHARMACY 1~ SPURS       0040~
## 6 201836 2018-09-02   2018-09-08 4410677998~ PHARMACY 1~ SPURS       0059~
## # ... with 37 more variables: NDC_DESC <chr>, BRX_GRX_CD <chr>,
## #   NDC_QTY_MTRC <dbl>, NDC_PKG_SZ <dbl>, NDC_CASE_PK_QTY <dbl>, MFG_NAM <chr>,
## #   GCNSEQ_NBR <chr>, GCNSEQ_DESC <chr>, GCNSEQ_RTE_OF_ADMIN_DESC <chr>,
## #   GCNSEQ_DSG_FORM_CD <chr>, GCNSEQ_STR_DESC <chr>, DSPN_QTY_NDC_1WK <dbl>,
## #   DSPN_QTY_NDC_4WKS <dbl>, DSPN_QTY_NDC_13WKS <dbl>,
## #   DSPN_QTY_NDC_26WKS <dbl>, DSPN_QTY_GCN_1WK <dbl>, DSPN_QTY_GCN_4WKS <dbl>,
## #   DSPN_QTY_GCN_13WKS <dbl>, DSPN_QTY_GCN_26WKS <dbl>,
## #   PURCH_QTY_NDC_1WK_MTRC <dbl>, PURCH_QTY_NDC_4WKS_MTRC <dbl>,
## #   PURCH_QTY_NDC_13WKS_MTRC <dbl>, PURCH_QTY_NDC_26WKS_MTRC <dbl>,
## #   PURCH_QTY_GCN_1WK_MTRC <dbl>, PURCH_QTY_GCN_4WKS_MTRC <dbl>,
## #   PURCH_QTY_GCN_13WKS_MTRC <dbl>, PURCH_QTY_GCN_26WKS_MTRC <dbl>,
## #   COGS_PRC_MTRC <dbl>, DSPN_COGS_NDC_1WK <dbl>, DSPN_COGS_NDC_4WKS <dbl>,
## #   DSPN_COGS_NDC_13WKS <dbl>, DSPN_COGS_NDC_26WKS <dbl>,
## #   DSPN_COGS_GCN_1WK <dbl>, DSPN_COGS_GCN_4WKS <dbl>,
## #   DSPN_COGS_GCN_13WKS <dbl>, DSPN_COGS_GCN_26WKS <dbl>, mean_cogs <dbl>

Task 6: Defining Leakage

leakage is defined as difference between Dispense qty and Purchase qty.

If Dispense is more than Purchase that signifies pharmacy is buying from outside the contract.

If Purchase is more then it signifies normal business.

d5 <- d4 %>%
  mutate(
          Leakage_Variable_for_1Wk = DSPN_QTY_NDC_1WK - PURCH_QTY_NDC_1WK_MTRC,
         Leakage_Variable_for_4Wk = DSPN_QTY_NDC_4WKS - PURCH_QTY_NDC_4WKS_MTRC,
         Leakage_Variable_for_13Wk = DSPN_QTY_NDC_13WKS - PURCH_QTY_NDC_13WKS_MTRC,
         Leakage_Variable_for_26Wk = DSPN_QTY_NDC_26WKS - PURCH_QTY_NDC_26WKS_MTRC
    )
head(d5)
## # A tibble: 6 x 48
##   WK_NBR WK_BEGIN_DTE WK_END_DTE NCPDP_TOKEN PHRMCY_NAME BUY_GRP_NAM NDC  
##   <chr>  <chr>        <chr>      <chr>       <chr>       <chr>       <chr>
## 1 201836 2018-09-02   2018-09-08 4410677998~ PHARMACY 1~ SPURS       0007~
## 2 201836 2018-09-02   2018-09-08 4410677998~ PHARMACY 1~ SPURS       0017~
## 3 201836 2018-09-02   2018-09-08 4410677998~ PHARMACY 1~ SPURS       1249~
## 4 201836 2018-09-02   2018-09-08 4410677998~ PHARMACY 1~ SPURS       0000~
## 5 201836 2018-09-02   2018-09-08 4410677998~ PHARMACY 1~ SPURS       0040~
## 6 201836 2018-09-02   2018-09-08 4410677998~ PHARMACY 1~ SPURS       0059~
## # ... with 41 more variables: NDC_DESC <chr>, BRX_GRX_CD <chr>,
## #   NDC_QTY_MTRC <dbl>, NDC_PKG_SZ <dbl>, NDC_CASE_PK_QTY <dbl>, MFG_NAM <chr>,
## #   GCNSEQ_NBR <chr>, GCNSEQ_DESC <chr>, GCNSEQ_RTE_OF_ADMIN_DESC <chr>,
## #   GCNSEQ_DSG_FORM_CD <chr>, GCNSEQ_STR_DESC <chr>, DSPN_QTY_NDC_1WK <dbl>,
## #   DSPN_QTY_NDC_4WKS <dbl>, DSPN_QTY_NDC_13WKS <dbl>,
## #   DSPN_QTY_NDC_26WKS <dbl>, DSPN_QTY_GCN_1WK <dbl>, DSPN_QTY_GCN_4WKS <dbl>,
## #   DSPN_QTY_GCN_13WKS <dbl>, DSPN_QTY_GCN_26WKS <dbl>,
## #   PURCH_QTY_NDC_1WK_MTRC <dbl>, PURCH_QTY_NDC_4WKS_MTRC <dbl>,
## #   PURCH_QTY_NDC_13WKS_MTRC <dbl>, PURCH_QTY_NDC_26WKS_MTRC <dbl>,
## #   PURCH_QTY_GCN_1WK_MTRC <dbl>, PURCH_QTY_GCN_4WKS_MTRC <dbl>,
## #   PURCH_QTY_GCN_13WKS_MTRC <dbl>, PURCH_QTY_GCN_26WKS_MTRC <dbl>,
## #   COGS_PRC_MTRC <dbl>, DSPN_COGS_NDC_1WK <dbl>, DSPN_COGS_NDC_4WKS <dbl>,
## #   DSPN_COGS_NDC_13WKS <dbl>, DSPN_COGS_NDC_26WKS <dbl>,
## #   DSPN_COGS_GCN_1WK <dbl>, DSPN_COGS_GCN_4WKS <dbl>,
## #   DSPN_COGS_GCN_13WKS <dbl>, DSPN_COGS_GCN_26WKS <dbl>, mean_cogs <dbl>,
## #   Leakage_Variable_for_1Wk <dbl>, Leakage_Variable_for_4Wk <dbl>,
## #   Leakage_Variable_for_13Wk <dbl>, Leakage_Variable_for_26Wk <dbl>

Task 7: Computing Leakage Per Week

d6 <- d5 %>%
  mutate(Leakage_perWk_for_4Wk = Leakage_Variable_for_4Wk/4,
         Leakage_perWk_for_13Wk = Leakage_Variable_for_13Wk/13,
         Leakage_perWk_for_26Wk = Leakage_Variable_for_26Wk/26)
head(d6)
## # A tibble: 6 x 51
##   WK_NBR WK_BEGIN_DTE WK_END_DTE NCPDP_TOKEN PHRMCY_NAME BUY_GRP_NAM NDC  
##   <chr>  <chr>        <chr>      <chr>       <chr>       <chr>       <chr>
## 1 201836 2018-09-02   2018-09-08 4410677998~ PHARMACY 1~ SPURS       0007~
## 2 201836 2018-09-02   2018-09-08 4410677998~ PHARMACY 1~ SPURS       0017~
## 3 201836 2018-09-02   2018-09-08 4410677998~ PHARMACY 1~ SPURS       1249~
## 4 201836 2018-09-02   2018-09-08 4410677998~ PHARMACY 1~ SPURS       0000~
## 5 201836 2018-09-02   2018-09-08 4410677998~ PHARMACY 1~ SPURS       0040~
## 6 201836 2018-09-02   2018-09-08 4410677998~ PHARMACY 1~ SPURS       0059~
## # ... with 44 more variables: NDC_DESC <chr>, BRX_GRX_CD <chr>,
## #   NDC_QTY_MTRC <dbl>, NDC_PKG_SZ <dbl>, NDC_CASE_PK_QTY <dbl>, MFG_NAM <chr>,
## #   GCNSEQ_NBR <chr>, GCNSEQ_DESC <chr>, GCNSEQ_RTE_OF_ADMIN_DESC <chr>,
## #   GCNSEQ_DSG_FORM_CD <chr>, GCNSEQ_STR_DESC <chr>, DSPN_QTY_NDC_1WK <dbl>,
## #   DSPN_QTY_NDC_4WKS <dbl>, DSPN_QTY_NDC_13WKS <dbl>,
## #   DSPN_QTY_NDC_26WKS <dbl>, DSPN_QTY_GCN_1WK <dbl>, DSPN_QTY_GCN_4WKS <dbl>,
## #   DSPN_QTY_GCN_13WKS <dbl>, DSPN_QTY_GCN_26WKS <dbl>,
## #   PURCH_QTY_NDC_1WK_MTRC <dbl>, PURCH_QTY_NDC_4WKS_MTRC <dbl>,
## #   PURCH_QTY_NDC_13WKS_MTRC <dbl>, PURCH_QTY_NDC_26WKS_MTRC <dbl>,
## #   PURCH_QTY_GCN_1WK_MTRC <dbl>, PURCH_QTY_GCN_4WKS_MTRC <dbl>,
## #   PURCH_QTY_GCN_13WKS_MTRC <dbl>, PURCH_QTY_GCN_26WKS_MTRC <dbl>,
## #   COGS_PRC_MTRC <dbl>, DSPN_COGS_NDC_1WK <dbl>, DSPN_COGS_NDC_4WKS <dbl>,
## #   DSPN_COGS_NDC_13WKS <dbl>, DSPN_COGS_NDC_26WKS <dbl>,
## #   DSPN_COGS_GCN_1WK <dbl>, DSPN_COGS_GCN_4WKS <dbl>,
## #   DSPN_COGS_GCN_13WKS <dbl>, DSPN_COGS_GCN_26WKS <dbl>, mean_cogs <dbl>,
## #   Leakage_Variable_for_1Wk <dbl>, Leakage_Variable_for_4Wk <dbl>,
## #   Leakage_Variable_for_13Wk <dbl>, Leakage_Variable_for_26Wk <dbl>,
## #   Leakage_perWk_for_4Wk <dbl>, Leakage_perWk_for_13Wk <dbl>,
## #   Leakage_perWk_for_26Wk <dbl>

Task 8: Comparing Means

a) weekly average shows very less leakage maybe because of very less data to compare.

b) monthly average is maximum which might be because of selling inventory

c) Quarter data is best for analysing as inventory selling should have averaged out and report will be generated in a quarter not after half year,

d7 <- d6 %>% summarise(
    Mean_1Wk = mean(Leakage_Variable_for_1Wk),
    Mean_4Wk = mean(Leakage_perWk_for_4Wk),
    Mean_13Wk= mean(Leakage_perWk_for_13Wk),
    Mean_26Wk = mean(Leakage_perWk_for_26Wk))

head(d7)
## # A tibble: 1 x 4
##   Mean_1Wk Mean_4Wk Mean_13Wk Mean_26Wk
##      <dbl>    <dbl>     <dbl>     <dbl>
## 1    0.140     4.49      3.80      2.91

Task 9: Mapping Leakage for 13 weeks throughout the Pharmacies and Buying Groups

d8 <- d5 %>% select(PHRMCY_NAME, BUY_GRP_NAM, NDC_DESC, BRX_GRX_CD,
                          MFG_NAM, Leakage_Variable_for_13Wk, COGS_PRC_MTRC)
head(d8)
## # A tibble: 6 x 7
##   PHRMCY_NAME BUY_GRP_NAM NDC_DESC BRX_GRX_CD MFG_NAM Leakage_Variabl~
##   <chr>       <chr>       <chr>    <chr>      <chr>              <dbl>
## 1 PHARMACY 1~ SPURS       LYRICA ~ BRX        PFIZER~              900
## 2 PHARMACY 1~ SPURS       ADVAIR ~ BRX        GLAXOS~             1260
## 3 PHARMACY 1~ SPURS       SUBOXON~ BRX        INDIVI~             1040
## 4 PHARMACY 1~ SPURS       HUMALOG~ BRX        ELI LI~              170
## 5 PHARMACY 1~ SPURS       HYDROCO~ GRX        MALLIN~             2326
## 6 PHARMACY 1~ SPURS       HYDROCO~ GRX        ACTAVI~              204
## # ... with 1 more variable: COGS_PRC_MTRC <dbl>

Task 10: Determining Leakage in Dollar Amount

There is a leakage of $446,359,418 in 13 weeks.

d9 <- d8 %>% mutate(
    Dollar_Amount_Leakage = Leakage_Variable_for_13Wk * COGS_PRC_MTRC
)
head(d9)
## # A tibble: 6 x 8
##   PHRMCY_NAME BUY_GRP_NAM NDC_DESC BRX_GRX_CD MFG_NAM Leakage_Variabl~
##   <chr>       <chr>       <chr>    <chr>      <chr>              <dbl>
## 1 PHARMACY 1~ SPURS       LYRICA ~ BRX        PFIZER~              900
## 2 PHARMACY 1~ SPURS       ADVAIR ~ BRX        GLAXOS~             1260
## 3 PHARMACY 1~ SPURS       SUBOXON~ BRX        INDIVI~             1040
## 4 PHARMACY 1~ SPURS       HUMALOG~ BRX        ELI LI~              170
## 5 PHARMACY 1~ SPURS       HYDROCO~ GRX        MALLIN~             2326
## 6 PHARMACY 1~ SPURS       HYDROCO~ GRX        ACTAVI~              204
## # ... with 2 more variables: COGS_PRC_MTRC <dbl>, Dollar_Amount_Leakage <dbl>

Total Leakage

Annualy leakage is four times the quaterly value, which $1,785,437,672.

Almost $1.8 Bn annual loss in expected revenue.

Total_Leakage<-sum(d9$Dollar_Amount_Leakage)

print(Total_Leakage)
## [1] 446359418

Leakage by pharmacies

d10 <- d9 %>% select(PHRMCY_NAME, Dollar_Amount_Leakage) %>% 
  group_by(PHRMCY_NAME) %>%
  summarise(
    Leakage = sum(Dollar_Amount_Leakage)
  )
## `summarise()` ungrouping output (override with `.groups` argument)
head(d10)
## # A tibble: 6 x 2
##   PHRMCY_NAME    Leakage
##   <chr>            <dbl>
## 1 PHARMACY 1        884.
## 2 PHARMACY 10    -11695.
## 3 PHARMACY 100    -8273.
## 4 PHARMACY 1000    4995.
## 5 PHARMACY 1001  -68021.
## 6 PHARMACY 1002 2019171.

Percentage of total leakage per pharmacy

d11 <- d10 %>% mutate(
  Leakage_percent = as.integer((Leakage/446359418)*100)
) %>% filter(Leakage_percent >= 1)
print(d11)
## # A tibble: 5 x 3
##   PHRMCY_NAME      Leakage Leakage_percent
##   <chr>              <dbl>           <int>
## 1 PHARMACY 1338   6945934.               1
## 2 PHARMACY 1793 104679245.              23
## 3 PHARMACY 2631   6647050.               1
## 4 PHARMACY 2644  13987693.               3
## 5 PHARMACY 536  216808755.              48

Leakage plot by pharmacy name

d12 <- d11 %>% select(-Leakage)
ggplot(d12, aes(x=PHRMCY_NAME, y=Leakage_percent, fill = PHRMCY_NAME)) + 
  geom_bar(stat = "identity", width = 0.5) + 
  geom_text(aes(label=Leakage_percent), vjust=1.6, color="black", size=3.5)+
  theme_minimal()

##

Leakage plot by buying group

## `summarise()` ungrouping output (override with `.groups` argument)

##

Leakage plot by Drug

## `summarise()` ungrouping output (override with `.groups` argument)

## Thank You