rggplot2mapschoroplethr

How to Remove State Abbreviations from a Choroplethr Map


I'm working with a choroplethr map like the one below. How do I simply remove the state abbreviations?

enssster image description here

Here is the replication code:

library(choroplethr)
library(choroplethrMaps)

data(df_pop_state)
df_pop_state$value <- as.numeric(df_pop_state$value)

state_choropleth(df_pop_state, num_colors = 1,
                             title = "2012 State Population Estimates",
                             legend = "Population")

Solution

  • Thank you for using choroplethr. Note that Choroplethr uses R6 Objects. In fact, the state_choropleth function is just a convenience wrapper for the StateChoropleth R6 object:

    > state_choropleth
    function (df, title = "", legend = "", num_colors = 7, zoom = NULL, 
        reference_map = FALSE) 
    {
        c = StateChoropleth$new(df)
        c$title = title
        c$legend = legend
        c$set_num_colors(num_colors)
        c$set_zoom(zoom)
        if (reference_map) {
            if (is.null(zoom)) {
                stop("Reference maps do not currently work with maps that have insets, such as maps of the 50 US States.")
            }
            c$render_with_reference_map()
        }
        else {
            c$render()
        }
    }
    <bytecode: 0x7fdda6aa3a10>
    <environment: namespace:choroplethr>
    

    If you look at the source code you will see that there is a field on the object that does what you want: show_labels. It defaults to TRUE.

    We can get the result you want by simply creating your map using the StateChoropleth object (not the function) and setting show_labels to FALSE.

    c = StateChoropleth$new(df_pop_state)
    c$title = "2012 State Population Estimates"
    c$legend = "Population"
    c$set_num_colors(1)
    c$show_labels = FALSE
    c$render()
    

    enter image description here

    I chose this approach because, in general, I found that many functions in R have a large number of parameters, and that can be confusing. The downside is that functions are easier to document than objects (especially in R), so questions like this frequently come up.