load("/Users/abbiemckay/DataVis/project1/providerspokane.RDA")
names(providerspokane)
##  [1] "National.Provider.Identifier"                            
##  [2] "Last.Name.Organization.Name.of.the.Provider"             
##  [3] "First.Name.of.the.Provider"                              
##  [4] "Middle.Initial.of.the.Provider"                          
##  [5] "Credentials.of.the.Provider"                             
##  [6] "Gender.of.the.Provider"                                  
##  [7] "Entity.Type.of.the.Provider"                             
##  [8] "Street.Address.1.of.the.Provider"                        
##  [9] "Street.Address.2.of.the.Provider"                        
## [10] "City.of.the.Provider"                                    
## [11] "Zip.Code.of.the.Provider"                                
## [12] "State.Code.of.the.Provider"                              
## [13] "Country.Code.of.the.Provider"                            
## [14] "Provider.Type"                                           
## [15] "Medicare.Participation.Indicator"                        
## [16] "Place.of.Service"                                        
## [17] "HCPCS.Code"                                              
## [18] "HCPCS.Description"                                       
## [19] "HCPCS.Drug.Indicator"                                    
## [20] "Number.of.Services"                                      
## [21] "Number.of.Medicare.Beneficiaries"                        
## [22] "Number.of.Distinct.Medicare.Beneficiary.Per.Day.Services"
## [23] "Average.Medicare.Allowed.Amount"                         
## [24] "Average.Submitted.Charge.Amount"                         
## [25] "Average.Medicare.Payment.Amount"                         
## [26] "Average.Medicare.Standardized.Amount"
library(tidyverse)
## ── Attaching packages ─────────────────── tidyverse 1.3.0 ──
## ✓ ggplot2 3.2.1     ✓ purrr   0.3.3
## ✓ tibble  2.1.3     ✓ dplyr   0.8.3
## ✓ tidyr   1.0.0     ✓ stringr 1.4.0
## ✓ readr   1.3.1     ✓ forcats 0.4.0
## ── Conflicts ────────────────────── tidyverse_conflicts() ──
## x dplyr::filter() masks stats::filter()
## x dplyr::lag()    masks stats::lag()
library(ggplot2)
summary(providerspokane)
##  National.Provider.Identifier
##  Min.   :1.003e+09           
##  1st Qu.:1.276e+09           
##  Median :1.509e+09           
##  Mean   :1.516e+09           
##  3rd Qu.:1.771e+09           
##  Max.   :1.993e+09           
##                              
##                         Last.Name.Organization.Name.of.the.Provider
##  PATHOLOGY ASSOCIATES MEDICAL LABORATORIES LLC:  491               
##  MUELLER                                      :  109               
##  KING                                         :  105               
##  JOHNSON                                      :  103               
##  JONES                                        :   99               
##  LEE                                          :   99               
##  (Other)                                      :17972               
##  First.Name.of.the.Provider Middle.Initial.of.the.Provider
##         :  964                     :3583                  
##  MICHAEL:  630              M      :1571                  
##  JOHN   :  469              J      :1569                  
##  DAVID  :  434              A      :1506                  
##  ROBERT :  410              L      :1299                  
##  WILLIAM:  324              D      :1273                  
##  (Other):15747              (Other):8177                  
##  Credentials.of.the.Provider Gender.of.the.Provider Entity.Type.of.the.Provider
##  MD     :7497                 :  964                I:18014                    
##  M.D.   :4871                F: 5558                O:  964                    
##         :1322                M:12456                                           
##  PA-C   : 904                                                                  
##  ARNP   : 873                                                                  
##  D.O.   : 313                                                                  
##  (Other):3198                                                                  
##  Street.Address.1.of.the.Provider Street.Address.2.of.the.Provider
##  801 S STEVENS ST: 1663                    :10058                 
##  122 W 7TH AVE   : 1194           SUITE 200:  538                 
##  400 E 5TH AVE   : 1176           SUITE 310:  421                 
##  910 W 5TH AVE   : 1038           SUITE 100:  345                 
##  101 W 8TH AVE   :  820           SUITE 700:  311                 
##  105 W 8TH AVE   :  802           SUITE 400:  306                 
##  (Other)         :12285           (Other)  : 6999                 
##  City.of.the.Provider Zip.Code.of.the.Provider State.Code.of.the.Provider
##  SPOKANE:18978        992042654: 1663          WA:18975                  
##                       992021334: 1176          WI:    2                  
##                       992042349: 1125          WY:    1                  
##                       992042966: 1062                                    
##                       992042307:  702                                    
##                       992042302:  607                                    
##                       (Other)  :12643                                    
##  Country.Code.of.the.Provider              Provider.Type  
##  US:18978                     Diagnostic Radiology: 2414  
##                               Internal Medicine   : 1809  
##                               Family Practice     : 1541  
##                               Physician Assistant : 1240  
##                               Nurse Practitioner  : 1214  
##                               Hematology/Oncology :  745  
##                               (Other)             :10015  
##  Medicare.Participation.Indicator Place.of.Service   HCPCS.Code   
##  N:    2                          F: 6157          99213  :  820  
##  Y:18976                          O:12821          99214  :  742  
##                                                    99204  :  316  
##                                                    99203  :  312  
##                                                    99232  :  286  
##                                                    99212  :  261  
##                                                    (Other):16241  
##                                                                   HCPCS.Description
##  Established patient office or other outpatient visit, typically 15 minutes:  820  
##  Established patient office or other outpatient, visit typically 25 minutes:  742  
##  New patient office or other outpatient visit, typically 45 minutes        :  316  
##  New patient office or other outpatient visit, typically 30 minutes        :  312  
##  Subsequent hospital inpatient care, typically 25 minutes per day          :  286  
##  Established patient office or other outpatient visit, typically 10 minutes:  261  
##  (Other)                                                                   :16241  
##  HCPCS.Drug.Indicator Number.of.Services Number.of.Medicare.Beneficiaries
##  N:17844              Min.   :    11.0   Min.   :   11.0                 
##  Y: 1134              1st Qu.:    20.0   1st Qu.:   17.0                 
##                       Median :    42.0   Median :   31.0                 
##                       Mean   :   291.2   Mean   :  101.8                 
##                       3rd Qu.:   115.0   3rd Qu.:   71.0                 
##                       Max.   :155972.0   Max.   :70013.0                 
##                                                                          
##  Number.of.Distinct.Medicare.Beneficiary.Per.Day.Services
##  Min.   :    11.0                                        
##  1st Qu.:    19.0                                        
##  Median :    39.0                                        
##  Mean   :   154.1                                        
##  3rd Qu.:   101.0                                        
##  Max.   :155971.0                                        
##                                                          
##  Average.Medicare.Allowed.Amount Average.Submitted.Charge.Amount
##  Min.   :    0.019               Min.   :    0.23               
##  1st Qu.:   19.003               1st Qu.:   48.00               
##  Median :   56.170               Median :  132.00               
##  Mean   :  104.731               Mean   :  295.21               
##  3rd Qu.:  107.572               3rd Qu.:  276.00               
##  Max.   :29872.890               Max.   :45998.00               
##                                                                 
##  Average.Medicare.Payment.Amount Average.Medicare.Standardized.Amount
##  Min.   :    0.011               Min.   :    0.011                   
##  1st Qu.:   15.498               1st Qu.:   15.990                   
##  Median :   40.720               Median :   43.613                   
##  Mean   :   80.178               Mean   :   83.320                   
##  3rd Qu.:   81.984               3rd Qu.:   85.360                   
##  Max.   :23420.340               Max.   :21855.610                   
## 
str(providerspokane$Place.of.Service)
##  Factor w/ 2 levels "F","O": 1 1 2 2 2 2 2 2 1 2 ...
levels(providerspokane$Place.of.Service)=c("Facility","Non-Facility")

#average medicare payment at facilities and non-facilities

Place_AMPA = providerspokane%>%
  group_by(Place.of.Service)%>%
  summarise(mean_medicare_paid = mean(Average.Medicare.Payment.Amount))

ggplot(Place_AMPA, mapping = aes(Place.of.Service, mean_medicare_paid, fill = Place.of.Service)) +geom_bar(stat = "identity")

#average submitted charge amount for facilities and non-facilities

Place_ASCA = providerspokane%>%
  group_by(Place.of.Service)%>%
  summarise(mean_submitted_charge_amount = mean(Average.Submitted.Charge.Amount))

ggplot(Place_ASCA, mapping = aes(Place.of.Service, mean_submitted_charge_amount, fill = Place.of.Service)) +geom_bar(stat = "identity")

#average number of services at facilities and non facilities

Place_ANOS = providerspokane%>%
  group_by(Place.of.Service)%>%
  summarise(average_number_of_services = mean(Number.of.Services))

ggplot(Place_ANOS, mapping = aes(Place.of.Service,average_number_of_services, fill = Place.of.Service )) +geom_bar(stat = "identity")

#average number of beneficiary services per day at facilities and non-facilities

Place_ANBS = providerspokane%>%
  group_by(Place.of.Service)%>%
  summarise(average_number_of_beneficiary_services = mean(Number.of.Distinct.Medicare.Beneficiary.Per.Day.Services))

ggplot(Place_ANBS, mapping = aes(Place.of.Service,average_number_of_beneficiary_services, fill = Place.of.Service )) +geom_bar(stat = "identity")