Why doesn't this map of covid-19 cases in california counties show San Francisco as having at least some cases?

data = ResourceData["Epidemic Data for Novel Coronavirus COVID-19", 

calData = 
  Module[{s = {}}, 
   Do[If[data[[k]][[1]] == Interpreter["USState"]["California"], 
     s = Join[s, {data[[k]][[2]]}]], {k, 1, Length[data]}]; s];

usaCountyCases[s_, c_] := 
 First[data[Select[MatchQ[Interpreter["USState"][s], #State] &]][
        Interpreter["USCounty"][c <> " county, " <> s], #County] &]][
    All, #ConfirmedCases["LastValue"] &] // Normal, 0]

caCountyCases[countycode_] := 
 usaCountyCases["Ca", calData[[countycode]][[2]][[1]]]

countiesValues = 
  Table[calData[[k]] -> caCountyCases[k] , {k, 1, Length[calData]}];

min = 0;

max = 100;

GeoRegionValuePlot[countiesValues, PlotRange -> {min, max, Automatic},
  ImageSize -> Full]

1 Answer 1


You're querying the data in a complicated way. For San Francisco, you'll have usaCountyCases["Ca", "SanFranciscoCounty"], and inside the code it becomes Interpreter["USCounty"]["SanFranciscoCounty county, Ca"]. The string is so invalid that the Interpreter fails to interprete:

No US county interpretation found. Try again.

Actually, if the plot is what you only desire, here's all the code you need:

data = ResourceData["Epidemic Data for Novel Coronavirus COVID-19", 

countiesValues =
 data[Select[#State == Interpreter["USState"]["California"] &],
     {"County", "ConfirmedCases"}][
    {"ConfirmedCases" -> (#["LastValue"] &)}][
   Apply[Rule]] // Normal;

GeoRegionValuePlot[countiesValues, PlotRange -> 1000, 
 ImageSize -> Full]

... where you get the correct figure 3400 for San Francisco.

  • $\begingroup$ Thanks! The code I was using was a lot slower. How would I make the GeoRegionValuePlot have tooltips which gives (hopefully) both county name and covid-19 cases. TIA $\endgroup$ Jun 28, 2020 at 13:14
  • $\begingroup$ @VeritasLux You can refer to GeoLabels option of GeoRegionValuePlot. But this is another question and a new post is suggested. $\endgroup$ Jun 28, 2020 at 14:36

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.