mountainMath/cansim

Add GEO.abb province/territory short names and GEO factor ordering

Closed this issue · 5 comments

For graphing all regions it is nice to have short names (2 char abbreviations) for the regions. This can be done outside the package, but it might be nice to have the named vector available in the package to make the quick conversion. It would be nice to then allow factor ordering to coincide with the geographic ordering. Shown below.

In English:

short_prov <- c(
  "British Columbia"="BC",
  "Alberta"="AB",
  "Saskatchewan"="SK",
  "Manitoba"="MB",
  "Ontario"="ON",
  "Quebec"="QC",
  "New Brunswick"="NB",
  "Prince Edward Island"="PE",
  "Nova Scotia"="NS",
  "Newfoundland and Labrador"="NL",
  "Yukon"="YT",
  "Northwest Territories"="NT",
  "Nunavut"="NU",
  "Northwest Territories including Nunavut"="NTNU",
  "Canada"="CAN"
)

And in French:

short_prov.fr <- c(
  "Colombie-Britannique"="BC",
  "Alberta"="AB",
  "Saskatchewan"="SK",
  "Manitoba"="MB",
  "Ontario"="ON",
  "Québec"="QC",
  "Nouveau-Brunswick"="NB",
  "Île-du-Prince-Édouard"="PE",
  "Nouvelle-Écosse"="NS",
  "Terre-Neuve-et-Labrador"="NL",
  "Yukon"="YT",
  "Territoires du Nord-Ouest"="NT",
  "Nunavut"="NU",
  "Territoires du Nord-Ouest incluant Nunavut"="NTNU",
  "Canada"="CAN"
)

You could then create the GEO.abb variable easily using:

df <- df %>%
  mutate(GEO.abb=short_prov[GEO],
         GEO.abb=factor(GEO.abb, levels=c("CAN","BC","AB","SK","MB","ON","QC","NB","PE","NS","NL","YT","NT","NU","NTNU")))

Note: the French version would require "GÉO" with the accent.

@blakeshaffer sorry just getting to this.

I think this would be a nice quality of life improvement with a pretty minimal impact to the repo code. I'll add it to the backlog of changes, thanks.

Alternatively, if you want to try your hand at contributing directly, would you be interested in opening a pull request with these changes?

Not sure what the status on this is. Do we want to add that into the code base? At the very least we should add the short_prov definitions. We could add a convenience function to set these, maybe another option in normalize_cansim_values. But I am thinking it should probably be a separate function, as it only applies to exactly those tables that (only) have provincial data.

Maybe just have a function called "add_provincial_abbreviations"?

Ok, added a separate function add_provincial_abbreviations into branch https://github.com/mountainMath/cansim/tree/fix_hierarchies that's due to get pulled into master in #64. Maybe @blakeshaffer can check if it works as expected.

Pulled into master. I'll leave this open for feedback if its working as expected, but it shouldn't have any downsides if not.

Added in #64