I am trying to create choropleth map based on zipcodes using the choroplethrZip package. My question is related to this post. I am having the same problem, where Alaska and Hawaii are not updated if I change colormap using the scale_fill_brewer.
My data is a simple dataframe with two columns, something like this.
region value
1 00501 1052
2 00544 635
3 00601 717
4 00602 264
5 00603 1275
6 00604 4
If I create my choropleth with the default function call.
zip_choropleth(df_sample,
title="Sample Cases",
legend="Cases")
[Here is what I get][2]
When I change the fill using the scale_fill_brewer, all the map is changed, expect Alaska and Hawaii, here is the code:
zip_choropleth(df_sample,
title="Sample Cases",
legend="Cases") + scale_fill_brewer(type="seq"
,palette="RdPu"
, direction = 1)
[Here is the new choropleth with Alaska and Hawaii unchanged.][3]
First, you can see what is happening. Also, the statelines are not drawn, I would like to add them if possible. When I tried to use the example in this post. Here is what I get.
choro = zip_choropleth$new(df_sample)
Gives the following error: Error in zip_choropleth$new : object of type 'closure' is not subsettable
.
Now, I am shooting in the dark, so I tried another way:
choro = zip_choropleth(df_sample)
choro$title = "Sample Cases"
choro$ggplot_scale = scale_fill_brewer(name="Cases", palette="RdPu", drop=FALSE)
choro$render()
The last command creates a error Error: attempt to apply non-function
.
I am not sure if this clarifies the problem. Hope you can help.
Here is the solution:
choro = ZipChoropleth$new(df_sample)
choro$title = "Sample Cases"
choro$ggplot_scale = scale_fill_brewer(name="Cases", palette="RdPu", drop=FALSE)
choro$render()
This updates Alaska and Hawaii with the new palette, but changes the lines of the zipcode areas and messes the drawing. At least I go the first problem taken care of. Alaska and Hawaii updated.