2
$\begingroup$

To start:

FLcounties = 
  AdministrativeDivisionData[
   Entity["AdministrativeDivision", {"Florida", "UnitedStates"}], 
   "Subdivisions"];

FLcountiespop = 
  AdministrativeDivisionData[#, "Population"] & /@ FLcounties;

ds = Dataset[AssociationThread[FLcounties -> FLcountiespop]];

FLPopulationMap = 
 GeoRegionValuePlot[ds, GeoBackground -> None, ImageSize -> 600, 
  GeoLabels -> (Tooltip[#1, 
      Row[{#2, ": ", EntityValue[#2, "PopulationDensity"]}]] &), 
  ColorFunctionScaling -> False, 
  ColorFunction -> (If[# > 2500000, Purple, 
      If[# > 2000000, Red, 
       If[# > 1500000, Orange, 
        If[# > 1000000, Yellow, If[# > 500000, Green, Blue]]]]] &), 
      PlotStyle -> Opacity[.3], 
      PlotLegends -> 
       BarLegend[Automatic, LegendFunction -> "Frame", 
        LegendLabel -> "Population", 
        LabelStyle -> Directive[Black, Bold, FontSize -> 16]]]

The above should build a population map for all the counties in Florida; accompanied by a bar legend. If you now look at the bar legend of this map; what I' m attempting is to modify the NumberForm of the bar legend; so that the population values appear as: 2,500,000; 2,000,000; 1,500,000; 1,000,000; 500,000 instead of in exponential form as above. I have attempted substituting:

LabelStyle -> 
  Directive[Black, Bold, FontSize -> 16]

above with:

LabelStyle -> 
   Directive[NumberForm[#, DigitBlock -> 3], Black, Bold, 
    FontSize -> 16]]

or

LabelingFunction -> (Style[NumberForm[#, DigitBlock -> 3], 
Bold, Black, 16] &)

but, I get the following error message : "An improperly formatted directive with head NumberForm was encountered." I thank you for any help that you could provide!

$\endgroup$
4
$\begingroup$

Use the (undocumented) option "Ticks" in BarLegend:

BarLegend[Automatic, 
    LegendFunction -> "Frame", 
    LegendLabel -> "Population",
    "Ticks" -> Map[{#, NumberForm[#, DigitBlock -> 3]} &, 100000 Range[5, 25, 5]],
    LabelStyle -> Directive[Black, Bold, FontSize -> 16]]]

enter image description here

You can also use Ticks in place of "Ticks".

$\endgroup$
  • $\begingroup$ Thank you @kglr, I accept your answer! Thank you also for your feedback when you add that this option is undocumented. I notice that when I use either "Ticks" or Ticks (as you suggested); the word Ticks turns red as if it is not part of the Bar Legend repertoire of options. But, the important thing is that this option works. $\endgroup$ – Gilmar Rodriguez Pierluissi Aug 19 at 14:04
  • $\begingroup$ @Gilmar, thank you for the accept. BTW, may I suggest you revisit your previous questions and see if any answers are worth accepting. $\endgroup$ – kglr Aug 21 at 13:39
0
$\begingroup$

The following is added to review the above amendment of the legend and to add county names to the map (for the sake of completeness):

FLcounties = 
  AdministrativeDivisionData[
   Entity["AdministrativeDivision", {"Florida", "UnitedStates"}], 
   "Subdivisions"];

FLcountiespop = 
  AdministrativeDivisionData[#, "Population"] & /@ FLcounties;

ds = Dataset[AssociationThread[FLcounties -> FLcountiespop]];

FLPopulationMap = 
 GeoRegionValuePlot[ds, GeoBackground -> None, ImageSize -> 600, 
  GeoLabels -> (Tooltip[#1, 
      Row[{#2, ": ", EntityValue[#2, "PopulationDensity"]}]] &), 
  ColorFunctionScaling -> False, 
  ColorFunction -> (If[# > 2500000, Purple, 
      If[# > 2000000, Red, 
       If[# > 1500000, Orange, 
        If[# > 1000000, Yellow, If[# > 500000, Green, Blue]]]]] &), 
  PlotStyle -> Opacity[.3], 
  PlotLegends -> 
   BarLegend[Automatic, LegendFunction -> "Frame", 
    LegendLabel -> "Population", 
    "Ticks" -> 
     Map[{#, NumberForm[#, DigitBlock -> 3]} &, 
      100000 Range[5, 25, 5]], 
    LabelStyle -> Directive[Black, Bold, FontSize -> 16]]]

The following steps are added to produce a map of Florida counties with their capitalized county names:

countynames = EntityValue[FLcounties, "Name"];

countyshortnames = StringDrop[#, -31] & /@ countynames[[All]];

countycapitalizednames = ToUpperCase[countyshortnames]

loc = EntityValue[FLcounties, "Position"];

MapOfFloridaWithCountyNames = 
  GeoGraphics[{EdgeForm[{Thick, Black}], GeoStyling["OutlineMap"], 
    Polygon /@ FLcounties, 
    Table[GeoMarker[loc[[j]], 
      Style[countycapitalizednames[[j]], TextAlignment -> Center, 
       Black, FontSize -> 9, Bold, FontFamily -> "Pallatino"], 
      "Scale" -> 1], {j, 1, Length@countycapitalizednames}]}, 
   GeoBackground -> None, ImageSize -> 1200];

FinalFLMap = 
 Show[MapOfFloridaWithCountyNames, FLPopulationMap, 
  GeoBackground -> None, ImageSize -> 1200]

To export the final map; define your working directory:

setDir := 
 Quiet@Check[SetDirectory@DirectoryName@$InputFileName, 
   SetDirectory@NotebookDirectory[]]

path = setDir

Export["Map_FL_Counties_Population_with_County_Names.png", FinalFLMap]

The map should look like this:

Map of Florida Population with County Names

$\endgroup$

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.