Choroplethr package enhancement (caption) - understanding R6 and functions

I am working to get Ari Lamstein's choroplethr R package to allow the specification of arguments including caption from ggplot2:labs(caption = "My caption here"). caption is failing. Example code:

state_choropleth(df_pop_state,
                 title      = "US 2012 State Population Estimates",
                 subtitle   = "California, Oregon, Washington",
                 legend     = "Population",
                 caption    = "Estimates from the 2012 5-year ACS",
                 num_colors = 1,
                 zoom       = c("california", "oregon", "washington"))

My current work is in: https://github.com/RickPack/choroplethr

Based on the @include lines at the top, it appears state_choropleth() (defined in state.R) uses code in this sequence: (1) choropleth.R, (2) usa.R, (3) state.R.

We see that subtitle() is working but caption is not:
image

I can easily enough add the caption by adding it a la the ggplot2 graphics of grammar:

state_choropleth(df_pop_state,
                 title      = "US 2012 State Population Estimates",
                 subtitle   = "California, Oregon, Washington",
                 legend     = "Population",
                 caption    = "Estimates from the 2012 5-year ACS",
                 num_colors = 1,
                 zoom       = c("california", "oregon", "washington")) + 
    ggplot2::labs(caption = "hi")

However, edits like this to choropleth.R are not working to show the caption when specified as an argument for state_choropleth(), unlike what worked for subtitle():

ggplot(self$choropleth.df, aes(long, lat, group = group)) +
        self$ggplot_polygon + 
        self$get_scale() +
        self$theme_clean() + 
        ggtitle(self$title, self$subtitle) + 
        ggplot2::labs(caption = self$caption) +
        self$projection

I suppose understanding the indication for the R6 use of self$ would help. I could easily model the existing use of ggtitle(self$title) for subtitle.

I added subtitle = "" to choropleth.R to the public list that "make up the public interface of the object" and that worked well. My addition of caption was apparently not sufficient.

I hope this helps someone familiar with R6 and / or the choroplethr / choroplethrZip packages to help. Thanks!

1 Like

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.