Search code examples
choroplethr

choroplethR: state_choropleth no longer handles AK and HI


I'm using the code directly from the documentation file:

library(choroplethr)
library(choroplethrMaps)
data(df_pop_state) 
state_choropleth(df_pop_state,
                 title  = "US 2012 State Population Estimates",
                 legend = "Population")

This yields the following warning:

Warning messages:
1: In private$zoom == "alaska" || private$zoom == "hawaii" :
  'length(x) = 51 > 1' in coercion to 'logical(1)'
2: In private$zoom == "alaska" || private$zoom == "hawaii" :
  'length(x) = 51 > 1' in coercion to 'logical(1)'

The resulting map does not properly display data for HI and AK

enter image description here

Is this due to a change in ggplot2? Please advise.


Solution

  • Off hand, I don't know (remember?) what that warning is about. But I believe that both AK and HI are getting rendered correctly.

    For example, the following code sets AK and HI to be the largest values in the dataset, and then renders the map. You can see that they become very dark:

    df_pop_state[2, 2]  = 40000000 # Alaska
    df_pop_state[12, 2] = 40000000 # Hawaii
    state_choropleth(df_pop_state)
    

    Map with AK and HI having large values

    If you'd like me to dig into what the warning is about, please create another question about it. (I am the author of choroplethr, but I haven't touched this code in several years).

    The general issue is this map is rendering actual longitude and latitude paths for the state borders - the "axes" are simply hidden. The complication is that AK and HI are obviously not really located where you see them on the final map. In the world of geography they are called "insets". choroplethr uses ggplot's "annotation" feature to separately render them and then place them on the map. They compication is that they all need to use the same scale. That warning is probably getting triggered at some point during the inset process. But off hand, I don't know what it is.