2
$\begingroup$

Here is the code I am using to get an image of the entire USA.

data = ResourceData["Epidemic Data for Novel Coronavirus COVID-19", 
   "USStates"][
  All, {#AdministrativeDivision, #ConfirmedCases[
         "LastValue"]} &]; GeoRegionValuePlot[data]
GeoRegionValuePlot[data]

How do I temporarily remove Alaska and Hawaii? How do I make it so that the colorfunction will have at least six colors with adequately many bins for the states with low incidence of covid-19? TIA

$\endgroup$
3
$\begingroup$

To remove Alaska and Hawaii:

1. Use GeoVariant[Entity["Country", "UnitedStates"], "DefaultMapArea"] as the option value for GeoRange:

GeoRegionValuePlot[data, 
 GeoRange -> GeoVariant[Entity["Country", "UnitedStates"], "DefaultMapArea"]]

enter image description here

2. Filter data to select the continental states:

continentalus = EntityList @ Interpreter["USStateClass"]["Continental US"];

cdata = Select[MemberQ[continentalus, #[[1]]] &]@data;

assoc = AssociationThread @@ Transpose[cdata];

GeoRegionValuePlot[assoc]

enter image description here

To refine colors:

1. Use the option PlotRange to use all the color contrast for the states with confirmed cases between min and max:

{min, max} = {0, 50000};

GeoRegionValuePlot[assoc, 
 GeoRange -> GeoVariant[Entity["Country", "UnitedStates"], "DefaultMapArea"], 
 PlotRange -> {min, max, Automatic}]

enter image description here

2. Define a piece-wise color function using a list of bin limits of your choice:

binlims = {0, 2000, 5000, 10000, 15000, 25000, 50000, 200000, 1000000};

colorF = Function[x, 
   Piecewise[Transpose[{ColorData[{"Rainbow", {0, Length[#] - 1}}] /@ 
         Range[0, Length[#] - 1], #}] & @
     BlockMap[#[[1]] <= x < #[[2]] &, binlims, 2, 1], Black]];

Legended[GeoRegionValuePlot[Map[colorF] @ assoc, 
  PlotStyle -> FaceForm[Opacity[.7]]], 
 SwatchLegend[colorF /@ binlims, BlockMap[Row[#, " - "] &, binlims, 2, 1]]]

enter image description here

Aside: You can also use GeoHistogram using state polygons as bins and Values[assoc] as height values:

GeoHistogram[assoc, Polygon /@ Keys[assoc], Values[assoc] &, 
 ColorFunction -> colorF, ColorFunctionScaling -> False, 
 PlotLegends -> SwatchLegend[colorF /@ binlims, 
   BlockMap[Row[#, " - "] &, binlims, 2, 1]]]

enter image description here

| improve this answer | |
$\endgroup$
  • 1
    $\begingroup$ Super. I was wondering if you could give me some insight into my other question, "How do I make it so that the colorfunction will have at least six colors with adequately many bins for the states with low incidence of covid-19"? $\endgroup$ – Veritas Lux Jun 25 at 22:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.