My goal today is to create a geofacet graph. I’m heavily relying on the Introduction to geofacet vignette. I’ve seen the graphs done with US states, but I’m excited to see them laid out for Australia.

The Data

I’m planning to work with the australian_outcomes.csv data, but I’ll have to use pivot_longer() so that there is only one column representing the different Australian territories.

animal_outcomes <- read_csv("animal_outcomes.csv")

animals_terr <- animal_outcomes %>%
  pivot_longer(cols = -c(1:3), names_to = "territory",
               values_to = "pet_count") %>%
  mutate(`animal type` = factor(animal_type, 
                              levels = c("Dogs", "Cats", "Wildlife",
                                         "Other Animals", "Livestock",
                                         "Horses")))

Visualizing Pet Frequency

You can’t (to my knowledge) use facet_wrap() with facet_geo(), but I wanted to see how the “map” below had (or hadn’t) changed over the last few decades. So I picked three years of data to show the same plot three times. (Note, I’m only showing the first code block for readability sake.)

The most striking conclusion from the plots below is that the number of wildlife rescues has gone up (specifically in Queensland). Dog and cat rescues seem to have gone down overall.

animals_terr %>%
  filter(territory != "Total") %>%
  filter(year == 1999) %>%
ggplot() +
  geom_bar(aes(x = `animal type`, y = pet_count, fill = `animal type`), 
           stat = "identity") +
  geofacet::facet_geo( ~territory, grid = "aus_grid1") +
  scale_y_continuous(breaks = c(0,10000, 20000)) +
  coord_flip() + 
  labs(title = "Rescue pet frequency (1999) across Australian territories",
       y = "Frequency",
       caption = "Data Source: Royal Society for the Prevention of Cruelty to Animals, https://www.rspca.org.au/what-we-do/our-role-caring-animals/annual-statistics") +
  theme_bw() 

FYI, the geofacet package has a bazillion fantastic grids to choose from!!

get_grid_names()
##   [1] "us_state_grid1"                           
##   [2] "us_state_grid2"                           
##   [3] "eu_grid1"                                 
##   [4] "aus_grid1"                                
##   [5] "sa_prov_grid1"                            
##   [6] "gb_london_boroughs_grid"                  
##   [7] "nhs_scot_grid"                            
##   [8] "india_grid1"                              
##   [9] "india_grid2"                              
##  [10] "argentina_grid1"                          
##  [11] "br_states_grid1"                          
##  [12] "sea_grid1"                                
##  [13] "mys_grid1"                                
##  [14] "fr_regions_grid1"                         
##  [15] "de_states_grid1"                          
##  [16] "us_or_counties_grid1"                     
##  [17] "us_wa_counties_grid1"                     
##  [18] "us_in_counties_grid1"                     
##  [19] "us_in_central_counties_grid1"             
##  [20] "se_counties_grid1"                        
##  [21] "sf_bay_area_counties_grid1"               
##  [22] "ua_region_grid1"                          
##  [23] "mx_state_grid1"                           
##  [24] "mx_state_grid2"                           
##  [25] "scotland_local_authority_grid1"           
##  [26] "us_state_without_DC_grid1"                
##  [27] "italy_grid1"                              
##  [28] "italy_grid2"                              
##  [29] "be_province_grid1"                        
##  [30] "us_state_grid3"                           
##  [31] "jp_prefs_grid1"                           
##  [32] "ng_state_grid1"                           
##  [33] "bd_upazila_grid1"                         
##  [34] "spain_prov_grid1"                         
##  [35] "ch_cantons_grid1"                         
##  [36] "ch_cantons_grid2"                         
##  [37] "china_prov_grid1"                         
##  [38] "world_86countries_grid"                   
##  [39] "se_counties_grid2"                        
##  [40] "uk_regions1"                              
##  [41] "us_state_contiguous_grid1"                
##  [42] "sk_province_grid1"                        
##  [43] "ch_aargau_districts_grid1"                
##  [44] "jo_gov_grid1"                             
##  [45] "spain_ccaa_grid1"                         
##  [46] "spain_prov_grid2"                         
##  [47] "world_countries_grid1"                    
##  [48] "br_states_grid2"                          
##  [49] "china_city_grid1"                         
##  [50] "kr_seoul_district_grid1"                  
##  [51] "nz_regions_grid1"                         
##  [52] "sl_regions_grid1"                         
##  [53] "us_census_div_grid1"                      
##  [54] "ar_tucuman_province_grid1"                
##  [55] "us_nh_counties_grid1"                     
##  [56] "china_prov_grid2"                         
##  [57] "pl_voivodeships_grid1"                    
##  [58] "us_ia_counties_grid1"                     
##  [59] "us_id_counties_grid1"                     
##  [60] "ar_cordoba_dep_grid1"                     
##  [61] "us_fl_counties_grid1"                     
##  [62] "ar_buenosaires_communes_grid1"            
##  [63] "nz_regions_grid2"                         
##  [64] "oecd_grid1"                               
##  [65] "ec_prov_grid1"                            
##  [66] "nl_prov_grid1"                            
##  [67] "ca_prov_grid1"                            
##  [68] "us_nc_counties_grid1"                     
##  [69] "mx_ciudad_prov_grid1"                     
##  [70] "bg_prov_grid1"                            
##  [71] "us_hhs_regions_grid1"                     
##  [72] "tw_counties_grid1"                        
##  [73] "tw_counties_grid2"                        
##  [74] "af_prov_grid1"                            
##  [75] "us_mi_counties_grid1"                     
##  [76] "pe_prov_grid1"                            
##  [77] "sa_prov_grid2"                            
##  [78] "mx_state_grid3"                           
##  [79] "cn_bj_districts_grid1"                    
##  [80] "us_va_counties_grid1"                     
##  [81] "us_mo_counties_grid1"                     
##  [82] "cl_santiago_prov_grid1"                   
##  [83] "us_tx_capcog_counties_grid1"              
##  [84] "sg_planning_area_grid1"                   
##  [85] "in_state_ut_grid1"                        
##  [86] "cn_fujian_prov_grid1"                     
##  [87] "ca_quebec_electoral_districts_grid1"      
##  [88] "nl_prov_grid2"                            
##  [89] "cn_bj_districts_grid2"                    
##  [90] "ar_santiago_del_estero_prov_grid1"        
##  [91] "ar_formosa_prov_grid1"                    
##  [92] "ar_chaco_prov_grid1"                      
##  [93] "ar_catamarca_prov_grid1"                  
##  [94] "ar_jujuy_prov_grid1"                      
##  [95] "ar_neuquen_prov_grid1"                    
##  [96] "ar_san_luis_prov_grid1"                   
##  [97] "ar_san_juan_prov_grid1"                   
##  [98] "ar_santa_fe_prov_grid1"                   
##  [99] "ar_la_rioja_prov_grid1"                   
## [100] "ar_mendoza_prov_grid1"                    
## [101] "ar_salta_prov_grid1"                      
## [102] "ar_rio_negro_prov_grid1"                  
## [103] "uy_departamentos_grid1"                   
## [104] "ar_buenos_aires_prov_electoral_dist_grid1"
## [105] "europe_countries_grid1"                   
## [106] "argentina_grid2"                          
## [107] "us_state_without_DC_grid2"                
## [108] "jp_prefs_grid2"                           
## [109] "na_regions_grid1"                         
## [110] "mm_state_grid1"                           
## [111] "us_state_with_DC_PR_grid1"                
## [112] "fr_departements_grid1"                    
## [113] "ar_salta_prov_grid2"                      
## [114] "ie_counties_grid1"                        
## [115] "sg_regions_grid1"                         
## [116] "us_ny_counties_grid1"                     
## [117] "ru_federal_subjects_grid1"                
## [118] "us_ca_counties_grid1"                     
## [119] "lk_districts_grid1"                       
## [120] "us_state_without_DC_grid3"                
## [121] "co_cali_subdivisions_grid1"               
## [122] "us_in_northern_counties_grid1"            
## [123] "italy_grid3"                              
## [124] "us_state_with_DC_PR_grid2"                
## [125] "us_state_grid7"                           
## [126] "sg_planning_area_grid2"                   
## [127] "ch_cantons_fl_grid1"                      
## [128] "europe_countries_grid2"                   
## [129] "us_states_territories_grid1"              
## [130] "us_tn_counties_grid1"                     
## [131] "us_il_chicago_community_areas_grid1"      
## [132] "us_state_with_DC_PR_grid3"                
## [133] "in_state_ut_grid2"                        
## [134] "at_states_grid1"                          
## [135] "us_pa_counties_grid1"                     
## [136] "us_oh_counties_grid1"                     
## [137] "fr_departements_grid2"                    
## [138] "us_wi_counties_grid1"                     
## [139] "africa_countries_grid1"                   
## [140] "no_counties_grid1"                        
## [141] "tr_provinces_grid1"