4

To create a means of displaying information about the distribution of primary care providers, the population density and the average yearly Medicare expenditure per enrollee for each state, I would like to create a US map with the state boundaries indicated, and then display a tool tip box containing the data for that state when the cursor hovers over that state. CountryData["UnitedStates"] does not have a map that includes the state boundaries.

In addition, I would like to colorize the states to indicate the value of a given parameter for that state, such as age-adjusted average yearly cost per Medicare Enrollee, by reference to a color scale.

I have not been able to find the Mathematica 9 code for an interactive US map in the Mathematica demonstrations and I am interested in suggestions or working code that I could use. My level of proficiency with Mathematica 9 is somewhere between beginner and intermediate, so I appreciate the details that might not be necessary for explaining the solution to an experienced user.

Sektor
  • 3,320
  • 7
  • 27
  • 36
user8624
  • 51
  • 2

1 Answers1

1

Part of the code taken from the question posted by @Cormullion

       crimestats =   WolframAlpha[   "Murder rate by state", {{"PropertyRanking:CrimeData", 1}, 
        "ComputableData"}];
        crimestats =   MapThread[Rule, {crimestats[[All, 2]], #[[1]] & /@ crimestats[[All, 3]]}];
        usa = Import["http://code.google.com/apis/kml/documentation/us_states.kml","Data"];
        transform[s_] := StringTrim[s, Whitespace ~~ "(" ~~ ___ ~~ ")"];
        polygons =   Thread[transform["PlacemarkNames" /. usa[[1]]] -> ("Geometry" /. usa[[1]])];
        stateNames = Extract[stateNames,Position[stateNames, x_ /; x != "Alaska" && x !="Hawaii"]];
        origdata = (stateNames /. polygons)[[All, 2 ;;, 1]];
        values = stateNames /. crimestats;
        colors = Module[{val = values, min, max, int}, min = Min@val; 
                         max = Max@val; int = Floor[#/((max - min)/4)] + 1 & /@ val; 
                         ColorData[8, "ColorList"][[#]] & /@ int];
        Show[Graphics[
                       Table[{EdgeForm[Directive[Black, AbsoluteThickness[0.5]]], 
                       colors[[i]], Tooltip[Polygon[origdata[[i]]], 
                                         Column[{stateNames[[i]], values[[i]]}]]}, {i, Length@origdata}], 
                       AspectRatio -> Automatic, ImageSize -> Large]]
Zviovich
  • 9,308
  • 1
  • 30
  • 52