February 25, 2018

Mapping with the Government Finance Database

The Government Finance Database

Some of my colleagues (Kawika Pierson, Mike Hand, and Fred Thompson) have put together a convenient access point for the Government Finance data available from the Census. They published an article in PLoS One with the rationale; I want to build some maps from their project with extensible code and functions. The overall dataset is enormous. I have downloaded the whole thing and filtered out the states. It seems that read.csv works better than read_csv for this task.

Splitting the Data

A link to the .zip version for states is here. A link to the .zip version for counties is here. You have to download their data directly as a .zip and unzip. If you downbload the entire file, as I did, unzip it, and you can import it to \(R\) with read.csv.

library(dplyr)
GFD <- read.csv("~/Documents/The Government Finance Database_All Data.csv")
State.Data <- GFD %>% filter(Type_Code==0)
County.Data <- GFD %>% filter(Type_Code==1)
rm(GFD)

The basic maps

choroplethr makes the process of mapping data a bit too easy. It is locked down but it works very well. What I will require is a simple function to cleave off a particular year, the state name, and whatever series of data I wish to make; I will need to store the latter two with the name region for the state name and value for whatever data we wish to plot. Why? That is the way that state_choropleth() is designed. For the automated functions state_choropleth() and county_choropleth(), this is quite easy. You will notice that there are FIPS and name inner joins available for this.

library(choroplethr)
library(choroplethrMaps)
data(state.map)
names(state.map)
##  [1] "long"       "lat"        "order"      "hole"       "piece"     
##  [6] "group"      "id"         "GEO_ID"     "STATE"      "region"    
## [11] "LSAD"       "CENSUSAREA"
data(county.regions)
names(county.regions)
## [1] "region"                "county.fips.character" "county.name"          
## [4] "state.name"            "state.fips.character"  "state.abb"

Putting them together: States

Let’s see what we can do. The first step is that the state name conventions are inconsistent, though the FIPS codes, thankfully, do not change. I will convert them to strings, to drop the unused levels of the factors from import, and replace the state delineated names with a single standard name. The second relevant selector is going to be the year, Year4. Finally, I have to choose something to put in values. Let me try total revenue per capita in year 2015. dplyr is so neat that this can be done in only five lines. Define and name the object; filter by the year; mutate the data into the two things I need; select them off.

library(dplyr)
library(tidyverse)
State.Data$Name <- as.character(State.Data$Name)
State.Data$NameFixed <- gsub(" STATE GOVT","",State.Data$Name)
State.Data$NameFLower <- tolower(State.Data$NameFixed)
# Clean up the names and store the cleaned result
my.GFD.2015 <- State.Data %>% 
  filter(Year4==2015) %>%
  mutate(value = Total_Taxes / Population, region = NameFLower) %>%
  select(region, value)
my.GFD.2015
##            region    value
## 1         alabama 2.007714
## 2          alaska 1.169672
## 3         arizona 2.062385
## 4        arkansas 3.085824
## 5      california 3.861881
## 6        colorado 2.347743
## 7     connecticut 4.518299
## 8        delaware 3.714758
## 9         florida 1.835985
## 10        georgia 1.930886
## 11         hawaii 4.530280
## 12          idaho 2.402183
## 13       illinois 3.174292
## 14        indiana 2.628473
## 15           iowa 2.941598
## 16         kansas 2.707783
## 17       kentucky 2.620959
## 18      louisiana 2.076066
## 19          maine 3.057240
## 20       maryland 3.329998
## 21  massachusetts 3.975644
## 22       michigan 2.716768
## 23      minnesota 4.451924
## 24    mississippi 2.641045
## 25       missouri 1.965284
## 26        montana 2.752764
## 27       nebraska 2.682621
## 28         nevada 2.605809
## 29  new hampshire 1.869624
## 30     new jersey 3.523957
## 31     new mexico 2.882076
## 32       new york 3.950608
## 33 north carolina 2.497637
## 34   north dakota 7.583087
## 35           ohio 2.436590
## 36       oklahoma 2.405160
## 37         oregon 2.624777
## 38   pennsylvania 2.842799
## 39   rhode island 3.026298
## 40 south carolina 1.967472
## 41   south dakota 1.950109
## 42      tennessee 1.923927
## 43          texas 2.005396
## 44           utah 2.237496
## 45        vermont 4.860939
## 46       virginia 2.449827
## 47     washington 2.879141
## 48  west virginia 3.018220
## 49      wisconsin 2.948908
## 50        wyoming 4.020295

That is exactly the data that I need. Finally, add a title and continuous color scheming.

state_choropleth(my.GFD.2015, title="Total Taxes per capita", num_colors=1)
## Warning in self$bind(): The following regions were missing and are being set to
## NA: district of columbia

That’s far too easy. Total taxes, which I have not bothered to look up, appear to contain some unexpected details. What else can be done with it? The final code chunk does it all. To calculate a new map, just change the name of the thing per capitized. What data are available? See below….

names(State.Data)
##   [1] "SurveyYr"                     "Year4"                       
##   [3] "YearofData"                   "ID"                          
##   [5] "IDChanged"                    "State_Code"                  
##   [7] "Type_Code"                    "County"                      
##   [9] "Name"                         "FIPS_Code_State"             
##  [11] "FIPS_County"                  "FIPS_Place"                  
##  [13] "FYEndDate"                    "YearPop"                     
##  [15] "SchLevCode"                   "Population"                  
##  [17] "FunctionCode"                 "Enrollment"                  
##  [19] "Total_Revenue"                "Total_Rev_Own_Sources"       
##  [21] "General_Revenue"              "Gen_Rev_Own_Sources"         
##  [23] "Total_Taxes"                  "Property_Tax"                
##  [25] "Tot_Sales___Gr_Rec_Tax"       "Total_Gen_Sales_Tax"         
##  [27] "Total_Select_Sales_Tax"       "Alcoholic_Beverage_Tax"      
##  [29] "Amusement_Tax"                "Insurance_Premium_Tax"       
##  [31] "Motor_Fuels_Tax"              "Pari_mutuels_Tax"            
##  [33] "Public_Utility_Tax"           "Tobacco_Tax"                 
##  [35] "Other_Select_Sales_Tax"       "Total_License_Taxes"         
##  [37] "Alcoholic_Beverage_Lic"       "Amusement_License"           
##  [39] "Corporation_License"          "Hunting___Fishing_License"   
##  [41] "Motor_Vehicle_License"        "Motor_Veh_Oper_License"      
##  [43] "Motor_Vehicle_License_Total"  "Public_Utility_License"      
##  [45] "Occup_and_Bus_Lic_NEC"        "Other_License_Taxes"         
##  [47] "Total_Income_Taxes"           "Individual_Income_Tax"       
##  [49] "Corp_Net_Income_Tax"          "Death_and_Gift_Tax"          
##  [51] "Docum_and_Stock_Tr_Tax"       "Severance_Tax"               
##  [53] "Taxes_NEC"                    "Total_IG_Revenue"            
##  [55] "Total_Fed_IG_Revenue"         "Fed_IGR_Air_Transport"       
##  [57] "Fed_IGR_Education"            "Fed_IGR_Emp_Sec_Adm"         
##  [59] "Fed_IGR_Gen_Rev_Shar"         "Fed_IGR_Gen_Support"         
##  [61] "Fed_IGR_Health___Hos"         "Fed_IGR_Highways"            
##  [63] "Fed_IGR_Transit_Sub"          "Fed_IGR_Hous_Com_Dev"        
##  [65] "Fed_IGR_Natural_Res"          "Fed_IGR_Public_Welf"         
##  [67] "Fed_IGR_Sewerage"             "Fed_IGR_Other"               
##  [69] "Total_State_IG_Revenue"       "State_IGR_Education"         
##  [71] "State_IGR_Tax_Relief"         "State_IGR_Oth_Gen_Sup"       
##  [73] "State_IGR_Gen_Sup"            "State_IGR_Health___Hos"      
##  [75] "State_IGR_Highways"           "State_IGR_Transit_Sub"       
##  [77] "State_IGR_Hous_Com_Dev"       "State_IGR_Public_Welf"       
##  [79] "State_IGR_Sewerage"           "State_IGR_Other"             
##  [81] "Tot_Local_IG_Rev"             "Local_IGR_InterSchool_Aid"   
##  [83] "Local_IGR_Other_Education"    "Local_IGR_Oth_Gen_Sup"       
##  [85] "Local_IGR_Health___Hos"       "Local_IGR_Highways"          
##  [87] "Local_IGR_Transit_Sub"        "Local_IGR_Hous_Com_Dev"      
##  [89] "Local_IGR_Public_Welf"        "Local_IGR_Sewerage"          
##  [91] "Local_IGR_Other"              "Tot_Chgs_and_Misc_Rev"       
##  [93] "Total_General_Charges"        "Chg_Air_Transportation"      
##  [95] "Chg_Misc_Com_Activ"           "Chg_Total_Education"         
##  [97] "Chg_Total_Elem_Education"     "Chg_Elem_Ed_Sch_Lunch"       
##  [99] "Chg_Elem_Ed_Tuition"          "Chg_Elem_Ed_NEC"             
## [101] "Chg_Total_High_Ed"            "Chg_Hospitals"               
## [103] "Chg_Highways"                 "Chg_Regular_Highways"        
## [105] "Chg_Toll_Highways"            "Chg_Housing___Comm_Dev"      
## [107] "Chg_Total_Nat_Res"            "Chg_Parking"                 
## [109] "Chg_Parks___Recreation"       "Chg_Sewerage"                
## [111] "Chg_Solid_Waste_Mgmt"         "Chg_Water_Transport"         
## [113] "Chg_All_Other_NEC"            "Misc_General_Revenue"        
## [115] "Special_Assessments"          "Prop_Sale_Total"             
## [117] "Prop_Sale_Hous_Com_Dev"       "Prop_Sale_Other"             
## [119] "Interest_Revenue"             "Fines_and_Forfeits"          
## [121] "Rents_and_Royalties"          "Net_Lottery_Revenue"         
## [123] "Misc_General_Rev_NEC"         "Liquor_Stores_Revenue"       
## [125] "Total_Utility_Revenue"        "Water_Utility_Revenue"       
## [127] "Electric_Utility_Rev"         "Gas_Utility_Rev"             
## [129] "Transit_Utility_Rev"          "Total_Insur_Trust_Rev"       
## [131] "Total_Insur_Trust_Ctrb"       "Tot_Ins_Trust_Inv_Rev"       
## [133] "Total_Emp_Ret_Rev"            "Emp_Ret_Total_Ctrib"         
## [135] "Emp_Ret_Loc_Emp_Ctrib"        "Emp_Ret_Loc_To_Loc_Sys"      
## [137] "Emp_Ret_From_Other_Gov"       "Emp_Ret_Sta_To_Sta_Ctr"      
## [139] "Emp_Ret_Int_Rev"              "Emp_Ret_Other_Earnings"      
## [141] "Total_Unemp_Rev"              "Unemp_Payroll_Tax"           
## [143] "Unemp_Int_Revenue"            "Unemp_Federal_Advances"      
## [145] "Total_Expenditure"            "Total_IG_Expenditure"        
## [147] "Direct_Expenditure"           "Total_Current_Expend"        
## [149] "Total_Current_Oper"           "Total_Capital_Outlays"       
## [151] "Total_Construction"           "Total_Other_Capital_Outlays" 
## [153] "Tot_Assist___Subsidies"       "Total_Interest_on_Debt"      
## [155] "Total_Insur_Trust_Ben"        "Total_Salaries___Wages"      
## [157] "General_Expenditure"          "IG_Exp_To_State_Govt"        
## [159] "IG_Exp_To_Local_Govts"        "IG_Exp_To_Federal_Govt"      
## [161] "Direct_General_Expend"        "General_Current_Expend"      
## [163] "General_Current_Oper"         "General_Capital_Outlay"      
## [165] "General_Construction"         "General_Capital_Outlay_Other"
## [167] "General_Assist___Sub"         "General_Debt_Interest"       
## [169] "Air_Trans_Total_Expend"       "Air_Trans_Direct_Expend"     
## [171] "Air_Trans_Cap_Outlay"         "Air_Trans_Current_Exp"       
## [173] "Air_Trans_Construction"       "Air_Trans_IG_To_State"       
## [175] "Air_Trans_IG_Local_Govts"     "Misc_Com_Activ_Tot_Exp"      
## [177] "Misc_Com_Activ_Cap_Out"       "Misc_Com_Activ_Current_Exp"  
## [179] "Misc_Com_Activ_Constr"        "Correct_Total_Exp"           
## [181] "Correct_Direct_Exp"           "Correct_Cap_Outlay"          
## [183] "Correct_Current_Exp"          "Correct_Construct"           
## [185] "Correct_IG_To_St"             "Correct_IG_Loc_Govts"        
## [187] "Total_Educ_Total_Exp"         "Total_Educ_Direct_Exp"       
## [189] "Total_Educ_Assist___Sub"      "Total_Educ_Cap_Outlay"       
## [191] "Total_Educ_Current_Exp"       "Total_Educ_Construct"        
## [193] "Elem_Educ_Total_Exp"          "Elem_Educ_Direct_Exp"        
## [195] "Elem_Educ_Cap_Outlay"         "Elem_Educ_Current_Exp"       
## [197] "Elem_Educ_Construction"       "Elem_Educ_IG_To_State"       
## [199] "Elem_Educ_IG_Local_Govts"     "Elem_Educ_IG_Sch_to_Sch"     
## [201] "Higher_Ed_Total_Exp"          "Higher_Ed_Direct_Exp"        
## [203] "Higher_Ed_Cap_Outlay"         "Higher_Ed_Current_Exp"       
## [205] "Higher_Ed_Construct"          "Higher_Ed_IG_To_St"          
## [207] "Higher_Ed_IG_Loc_Govts"       "Educ_NEC_Total_Expend"       
## [209] "Educ_NEC_Direct_Expend"       "Educ_NEC_Assistance"         
## [211] "Educ_NEC_Cap_Outlay"          "Educ_NEC_Current_Exp"        
## [213] "Educ_NEC_Construction"        "Educ_NEC_IG_To_State"        
## [215] "Educ_NEC_IG_Local_Govts"      "Emp_Sec_Adm_Direct_Exp"      
## [217] "Emp_Sec_Adm_Cap_Outlay"       "Emp_Sec_Adm_Current_Exp"     
## [219] "Emp_Sec_Adm_Construct"        "Fin_Admin_Total_Exp"         
## [221] "Fin_Admin_Direct_Exp"         "Fin_Admin_Cap_Outlay"        
## [223] "Fin_Admin_Current_Exp"        "Fin_Admin_Construction"      
## [225] "Fin_Admin_IG_To_State"        "Fin_Admin_IG_Local_Govts"    
## [227] "Fire_Prot_Total_Expend"       "Fire_Prot_Direct_Exp"        
## [229] "Fire_Prot_Cap_Outlay"         "Fire_Prot_Current_Exp"       
## [231] "Fire_Prot_Construction"       "Fire_Prot_IG_To_State"       
## [233] "Fire_Prot_IG_Local_Govts"     "Judicial_Total_Expend"       
## [235] "Judicial_Direct_Expend"       "Judicial_Cap_Outlay"         
## [237] "Judicial_Current_Exp"         "Judicial_Construction"       
## [239] "Judicial_IG_To_State"         "Judicial_IG_Local_Govts"     
## [241] "Cen_Staff_Total_Expend"       "Cen_Staff_Direct_Exp"        
## [243] "Cen_Staff_Cap_Outlay"         "Cen_Staff_Current_Exp"       
## [245] "Cen_Staff_Construction"       "Cen_Staff_IG_To_State"       
## [247] "Cen_Staff_IG_Local_Govts"     "Gen_Pub_Bldg_Total_Exp"      
## [249] "Gen_Pub_Bldg_Cap_Out"         "Gen_Pub_Bldg_Current_Exp"    
## [251] "Gen_Pub_Bldg_Construct"       "Health_Total_Expend"         
## [253] "Health_Direct_Expend"         "Health_Capital_Outlay"       
## [255] "Health_Current_Exp"           "Health_Construction"         
## [257] "Health_IG_To_State"           "Health_IG_Local_Govts"       
## [259] "Total_Hospital_Total_Exp"     "Total_Hospital_Dir_Exp"      
## [261] "Total_Hospital_Cap_Out"       "Total_Hospital_Current_Exp"  
## [263] "Total_Hospital_Construct"     "Total_Hospital_IG_To_State"  
## [265] "Total_Hospital_IG_Loc_Govts"  "Own_Hospital_Total_Exp"      
## [267] "Own_Hospital_Cap_Out"         "Own_Hospital_Current_Exp"    
## [269] "Own_Hospital_Construct"       "Hosp_Other_Total_Exp"        
## [271] "Hosp_Other_Direct_Exp"        "Hosp_Other_Cap_Outlay"       
## [273] "Hosp_Other_Current_Exp"       "Hosp_Other_Construct"        
## [275] "Hosp_Other_IG_To_State"       "Hosp_Other_IG_Loc_Govts"     
## [277] "Total_Highways_Tot_Exp"       "Total_Highways_Dir_Exp"      
## [279] "Total_Highways_Cap_Out"       "Total_Highways_Current_Exp"  
## [281] "Total_Highways_Construct"     "Regular_Hwy_Total_Exp"       
## [283] "Regular_Hwy_Direct_Exp"       "Regular_Hwy_Cap_Outlay"      
## [285] "Regular_Hwy_Current_Exp"      "Regular_Hwy_Construct"       
## [287] "Regular_Hwy_IG_To_Sta"        "Regular_Hwy_IG_Loc_Govts"    
## [289] "Toll_Hwy_Total_Expend"        "Toll_Hwy_Cap_Outlay"         
## [291] "Toll_Hwy_Current_Exp"         "Toll_Hwy_Construction"       
## [293] "Transit_Sub_Total_Exp"        "Transit_Sub_Direct_Sub"      
## [295] "Transit_Sub_IG_To_Sta"        "Transit_Sub_IG_Loc_Govts"    
## [297] "Transit_Sub_To_Own_Sys"       "Hous___Com_Total_Exp"        
## [299] "Hous___Com_Direct_Exp"        "Hous___Com_Cap_Outlay"       
## [301] "Hous___Com_Current_Exp"       "Hous___Com_Construct"        
## [303] "Hous___Com_IG_To_State"       "Hous___Com_IG_Loc_Govts"     
## [305] "Libraries_Total_Expend"       "Libraries_Direct_Exp"        
## [307] "Libraries_Cap_Outlay"         "Libraries_Current_Exp"       
## [309] "Libraries_Construction"       "Libraries_IG_To_State"       
## [311] "Libraries_IG_Local_Govts"     "Natural_Res_Total_Exp"       
## [313] "Natural_Res_Direct_Exp"       "Natural_Res_Cap_Outlay"      
## [315] "Natural_Res_Current_Exp"      "Natural_Res_Construct"       
## [317] "Natural_Res_IG_To_Sta"        "Natural_Res_IG_Loc_Govts"    
## [319] "Parking_Total_Expend"         "Parking_Direct_Expend"       
## [321] "Parking_Capital_Outlay"       "Parking_Current_Exp"         
## [323] "Parking_Construction"         "Parking_IG_To_State"         
## [325] "Parking_IG_Local_Govts"       "Parks___Rec_Total_Exp"       
## [327] "Parks___Rec_Direct_Exp"       "Parks___Rec_Cap_Outlay"      
## [329] "Parks___Rec_Current_Exp"      "Parks___Rec_Construct"       
## [331] "Parks___Rec_IG_To_Sta"        "Parks___Rec_IG_Loc_Govts"    
## [333] "Police_Prot_Total_Exp"        "Police_Prot_Direct_Exp"      
## [335] "Police_Prot_Cap_Outlay"       "Police_Prot_Current_Exp"     
## [337] "Police_Prot_Construct"        "Police_Prot_IG_To_Sta"       
## [339] "Police_Prot_IG_Loc_Govts"     "Prot_Insp_Total_Exp"         
## [341] "Prot_Insp_Direct_Exp"         "Prot_Insp_Cap_Outlay"        
## [343] "Prot_Insp_Current_Exp"        "Prot_Insp_Construction"      
## [345] "Prot_Insp_IG_To_State"        "Prot_Insp_IG_Local_Govts"    
## [347] "Public_Welf_Total_Exp"        "Public_Welf_Direct_Exp"      
## [349] "Public_Welf_Cash_Asst"        "Public_Welf_Cap_Outlay"      
## [351] "Public_Welf_Current_Exp"      "Public_Welf_Construct"       
## [353] "Welf_Categ_Total_Exp"         "Welf_Categ_Cash_Assist"      
## [355] "Welf_Categ_IG_To_State"       "Welf_Categ_IG_Loc_Govts"     
## [357] "Welf_Cash_Total_Exp"          "Welf_Cash_Cash_Assist"       
## [359] "Welf_Cash_IG_Local_Govts"     "Welf_Vend_Pmts_Medical"      
## [361] "Welf_Vend_Pmts_NEC"           "Welf_State_Share_Part_D"     
## [363] "Welf_Ins_Total_Exp"           "Welf_Ins_Cap_Outlay"         
## [365] "Welf_Ins_Current_Exp"         "Welf_Ins_Construction"       
## [367] "Welf_NEC_Total_Expend"        "Welf_NEC_Direct_Expend"      
## [369] "Welf_NEC_Cap_Outlay"          "Welf_NEC_Current_Exp"        
## [371] "Welf_NEC_Construction"        "Welf_NEC_IG_To_State"        
## [373] "Welf_NEC_IG_Local_Govts"      "Sewerage_Total_Expend"       
## [375] "Sewerage_Direct_Expend"       "Sewerage_Cap_Outlay"         
## [377] "Sewerage_Current_Exp"         "Sewerage_Construction"       
## [379] "Sewerage_IG_To_State"         "Sewerage_IG_Local_Govts"     
## [381] "SW_Mgmt_Total_Expend"         "SW_Mgmt_Direct_Expend"       
## [383] "SW_Mgmt_Capital_Outlay"       "SW_Mgmt_Current_Exp"         
## [385] "SW_Mgmt_Construction"         "SW_Mgmt_IG_To_State"         
## [387] "SW_Mgmt_IG_Local_Govts"       "Water_Trans_Total_Exp"       
## [389] "Water_Trans_Direct_Exp"       "Water_Trans_Cap_Outlay"      
## [391] "Water_Trans_Current_Exp"      "Water_Trans_Construct"       
## [393] "Water_Trans_IG_To_Sta"        "Water_Trans_IG_Loc_Govts"    
## [395] "Interest_on_Gen_Debt"         "General_NEC_Total_Exp"       
## [397] "General_NEC_Direct_Exp"       "VetBonus"                    
## [399] "General_NEC_Cap_Outlay"       "General_NEC_Current_Exp"     
## [401] "General_NEC_Construct"        "General_NEC_IG_To_St"        
## [403] "General_NEC_IG_Loc_Govts"     "General_NEC_IG_To_Fed"       
## [405] "Liquor_Stores_Tot_Exp"        "Liquor_Stores_Cap_Out"       
## [407] "Liquor_Stores_Current_Exp"    "Liquor_Stores_Constr"        
## [409] "Total_Util_Total_Exp"         "Total_Util_Inter_Exp"        
## [411] "Total_Util_Cap_Outlay"        "Total_Util_Current_Exp"      
## [413] "Total_Util_Construct"         "Water_Util_Total_Exp"        
## [415] "Water_Util_Inter_Exp"         "Water_Util_Cap_Outlay"       
## [417] "Water_Util_Current_Exp"       "Water_Util_Construct"        
## [419] "Elec_Util_Total_Exp"          "Elec_Util_Inter_Exp"         
## [421] "Elec_Util_Cap_Outlay"         "Elec_Util_Current_Exp"       
## [423] "Elec_Util_Construct"          "Gas_Util_Total_Exp"          
## [425] "Gas_Util_Inter_Exp"           "Gas_Util_Cap_Outlay"         
## [427] "Gas_Util_Current_Exp"         "Gas_Util_Construct"          
## [429] "Trans_Util_Total_Exp"         "Trans_Util_Inter_Exp"        
## [431] "Trans_Util_Cap_Outlay"        "Trans_Util_Current_Exp"      
## [433] "Trans_Util_Construct"         "Emp_Ret_Total_Expend"        
## [435] "Emp_Ret_Benefit_Paymts"       "Emp_Ret_Withdrawals"         
## [437] "Emp_Ret_Other_Paymts"         "Unemp_Comp_Total_Exp"        
## [439] "Unemp_Comp_Ben_Paymts"        "Unemp_Ext___Spec_Pmts"       
## [441] "Total_Debt_Outstanding"       "Total_Long_Term_Debt_Out"    
## [443] "ST_Debt_End_of_Year"          "Total_Beg_LTD_Out"           
## [445] "Beg_LTD_Out_Private_Purp"     "Beg_LTD_Out_All_Other"       
## [447] "Beg_LTD_Out_Utility"          "Beg_LTD_Out_Water_Util"      
## [449] "Beg_LTD_Out_Elec_Util"        "Beg_LTD_Out_Gas_Util"        
## [451] "Beg_LTD_Out_Trans_Util"       "Beg_LTD_Out_General"         
## [453] "Beg_LTD_Out_Education"        "Beg_LTD_Out_Priv_Purp"       
## [455] "Beg_LTD_Out_Other_NEC"        "Total_LTD_Issued"            
## [457] "LTD_Iss_Private_Purp"         "LTD_Iss_All_Other"           
## [459] "LTD_Iss_Utility"              "LTD_Iss_Util_Water"          
## [461] "LTD_Iss_Util_Electric"        "LTD_Iss_Util_Gas_Supply"     
## [463] "LTD_Iss_Util_Transit"         "LTD_Iss_General"             
## [465] "LTD_Iss_Gen_Elem_Educ"        "LTD_Iss_Gen_Other_Educ"      
## [467] "LTD_Iss_Gen_Other_NEC"        "Total_LTD_Iss_FFC"           
## [469] "LTD_Iss_FFC_Utility"          "LTD_Iss_FFC_Water_Util"      
## [471] "LTD_Iss_FFC_Elec_Util"        "LTD_Iss_FFC_Gas_Util"        
## [473] "LTD_Iss_FFC_Trans_Util"       "LTD_Iss_FFC_General"         
## [475] "LTD_Iss_FFC_Elem_Educ"        "LTD_Iss_FFC_Other_Educ"      
## [477] "LTD_Iss_FFC_Other_NEC"        "Total_LTD_Iss_NG"            
## [479] "LTD_Iss_NG_Utility"           "LTD_Iss_NG_Water_Util"       
## [481] "LTD_Iss_NG_Elec_Util"         "LTD_Iss_NG_Gas_Util"         
## [483] "LTD_Iss_NG_Trans_Util"        "LTD_Iss_NG_General"          
## [485] "LTD_Iss_NG_Elem_Educ"         "LTD_Iss_NG_Other_Educ"       
## [487] "LTD_Iss_NG_Private_Purp"      "LTD_Iss_NG_Other_NEC"        
## [489] "Total_LTD_Iss_Unsp"           "LTD_Iss_Unsp_Utility"        
## [491] "LTD_Iss_Unsp_Water_Util"      "LTD_Iss_Unsp_Elec_Util"      
## [493] "LTD_Iss_Unsp_Gas_Util"        "LTD_Iss_Unsp_Trans_Util"     
## [495] "LTD_Iss_Unsp_General"         "LTD_Iss_Unsp_Elem_Educ"      
## [497] "LTD_Iss_Unsp_Other_Educ"      "LTD_Iss_Unsp_Other_NEC"      
## [499] "Total_LTD_Retired"            "LTD_Ret_Private_Purp"        
## [501] "LTD_Ret_All_Other"            "LTD_Ret_Utility"             
## [503] "LTD_Ret_Util_Water"           "LTD_Ret_Util_Electric"       
## [505] "LTD_Ret_Util_Gas_Supply"      "LTD_Ret_Util_Transit"        
## [507] "LTD_Ret_General"              "LTD_Ret_Gen_Elem_Educ"       
## [509] "LTD_Ret_Gen_Other_Educ"       "LTD_Ret_Gen_Other_NEC"       
## [511] "Total_LTD_Ret_FFC"            "LTD_Ret_FFC_Utility"         
## [513] "LTD_Ret_FFC_Water_Util"       "LTD_Ret_FFC_Elec_Util"       
## [515] "LTD_Ret_FFC_Gas_Util"         "LTD_Ret_FFC_Trans_Util"      
## [517] "LTD_Ret_FFC_General"          "LTD_Ret_FFC_Elem_Educ"       
## [519] "LTD_Ret_FFC_Other_Educ"       "LTD_Ret_FFC_Other_NEC"       
## [521] "Total_LTD_Ret_NG"             "LTD_Ret_NG_Utility"          
## [523] "LTD_Ret_NG_Water_Util"        "LTD_Ret_NG_Elec_Util"        
## [525] "LTD_Ret_NG_Gas_Util"          "LTD_Ret_NG_Trans_Util"       
## [527] "LTD_Ret_NG_General"           "LTD_Ret_NG_Elem_Educ"        
## [529] "LTD_Ret_NG_Other_Educ"        "LTD_Ret_NG_Private_Purp"     
## [531] "LTD_Ret_NG_Other_NEC"         "Total_LTD_Ret_Unsp"          
## [533] "LTD_Ret_Unsp_Utility"         "LTD_Ret_Unsp_Water_Util"     
## [535] "LTD_Ret_Unsp_Elec_Utili"      "LTD_Ret_Unsp_Gas_Util"       
## [537] "LTD_Ret_Unsp_Trans_Util"      "LTD_Ret_Unsp_General"        
## [539] "LTD_Ret_Unsp_Elem_Educ"       "LTD_Ret_Unsp_Other_Educ"     
## [541] "LTD_Ret_Unsp_Other_NEC"       "Total_LTD_Out"               
## [543] "LTD_Out_Private_Purp"         "LTD_Out_All_Other"           
## [545] "Total_LTD_Out_Utility"        "LTD_Out_Util_Water"          
## [547] "LTD_Out_Util_Electric"        "LTD_Out_Util_Gas_Supply"     
## [549] "LTD_Out_Util_Transit"         "LTD_Out_General"             
## [551] "LTD_Out_Gen_Elem_Educ"        "LTD_Out_Gen_Other_Educ"      
## [553] "LTD_Out_Gen_Other_NEC"        "Total_LTD_Out_FFC"           
## [555] "LTD_Out_FFC_Utility"          "LTD_Out_FFC_Water_Util"      
## [557] "LTD_Out_FFC_Elec_Util"        "LTD_Out_FFC_Gas_Util"        
## [559] "LTD_Out_FFC_Trans_Util"       "LTD_Out_FFC_General"         
## [561] "LTD_Out_FFC_Elem_Educ"        "LTD_Out_FFC_Other_Educ"      
## [563] "LTD_Out_FFC_Other_NEC"        "Tot_LTD_Out_NG"              
## [565] "LTD_Out_NG_Utility"           "LTD_Out_NG_Water_Util"       
## [567] "LTD_Out_NG_Elec_Util"         "LTD_Out_NG_Gas_Util"         
## [569] "LTD_Out_NG_Trans_Util"        "LTD_Out_NG_General"          
## [571] "LTD_Out_NG_Elem_Educ"         "LTD_Out_NG_Other_Educ"       
## [573] "LTD_Out_NG_Private_Purp"      "LTD_Out_NG_Other_NEC"        
## [575] "Total_Cash___Securities"      "Insur_Trust_Cash___Sec"      
## [577] "Emp_Retire_Cash___Sec"        "Emp_Retire_Cash___Dep"       
## [579] "Emp_Retire_Total_Sec"         "Emp_Retire_Sec_Tot_Fed"      
## [581] "Emp_Retire_Sec_S_L_Secur"     "Emp_Retire_Sec_Tot_Nong"     
## [583] "Emp_Retire_Sec_Corp_Bds"      "Emp_Retire_Sec_Corp_Stk"     
## [585] "Emp_Retire_Sec_Mortgages"     "Emp_Retire_Sec_Misc_Inv"     
## [587] "Emp_Retire_Sec_Oth_Nong"      "Unemp_Comp_Cash___Sec"       
## [589] "Unemp_Comp_Bal_In_US_Trs"     "Unemp_Comp_Other_Balance"    
## [591] "Nonin_Trust_Cash___Sec"       "Sinking_Fd_Cash___Sec"       
## [593] "Bond_Fd_Cash___Sec"           "Oth_Nonin_Fd_Cash___Sec"     
## [595] "NameFixed"                    "NameFLower"

Revenues per capita

Change it up with a recalcalculation of the data and a new map.

my.GFD.2015 <- State.Data %>% 
  filter(Year4==2015) %>%
  mutate(value = Total_Revenue / Population, region = NameFLower) %>%
  select(region, value)
state_choropleth(my.GFD.2015, title="Total Revenues per capita", num_colors=1)
## Warning in self$bind(): The following regions were missing and are being set to
## NA: district of columbia

Putting them together: Counties

This part is slightly harder. It would appear as though the Government Finance Data doesn’t have a combined FIPS code; this is the region in map. But, the data contain the state and county fips codes and we can recreate them with the state code times 1000 plus the county. After that, plot the General Revenue.

#County.Data.2 <- read.csv(paste0(here(),"/data/CountyData.csv")
#County.Data.2 <- County.Data.2 %>% mutate(region = FIPS_Code_State* 1000 + FIPS_County)
#my.County.GFD.2015 <- County.Data.2 %>% 
#  filter(Year4==2012) %>% mutate(value = General_Revenue / Population) %>%
#  select(region, value)
county_choropleth(my.County.GFD.2015, title="General Revenue per capita")

The zoom feature is pretty cool: there are two defined forms for the county and states. The naming conventions follow the county.regions format and are lower case. Let me grab oregon.

#my.County.GFD.2015 <- County.Data.2 %>% 
#  filter(Year4==2012) %>% mutate(value = General_Revenue / Population) %>%
#  select(region, value)
county_choropleth(my.County.GFD.2015, title="General Revenue per capita", state_zoom="oregon")