1
$\begingroup$

I have a list of members of a team, and I want to create a visualization on a world map. I want to plot them on a map, to see some clustering.

The fields are: Person Name, City, State, Country

City and State may be blank. I'm envisioning using color intensity on the country to reflect how many of the members are on a given country, plus a circle on the cities, with circle size proportional to the count of people on that city.

Appreciate any help from the Mathematica experts on this forum, as my last usage of Mathematica is quite dated (v4 or 5)

Thanks!


EDIT

The fields I was referring to on the original question are on a spreadsheet. After I started trying to work out a solution, I settled on the following format:

a = {{{"","","India"},25},{{"","","China"},22},{{"New York ", "NY", "United States"},
10}, {{"San Francisco ", "CA", "United States"}, 
8}, {{"Boston  ", "MA", "United States"}, 4}, {{"Arlington", "MA", "United States"}, 
2}, {{"Arlington", "VA", "United States"}, 1}, {{"Cambridge", "MA", "United States"}, 
1}, {{"Needham", "MA", "United States"}, 1}, {{"Acton", "MA", "United States"}, 
1}, {{"Brooklyn", "NY", "United States"}, 1}, {{"Los Altos", "CA", "United States"}, 
1}, {{"Miami", "FL", "United States"}, 1}}

As you can see, some records will come with a blank city and state, only country.

$\endgroup$
7
  • 1
    $\begingroup$ Hello, you can start from 4928. In general, CountryData documentation is quite ilustrative too. $\endgroup$
    – Kuba
    Commented May 13, 2014 at 19:09
  • 1
    $\begingroup$ Unfortunately belisarius has not shared the code with us there $\endgroup$
    – Kuba
    Commented May 13, 2014 at 19:26
  • $\begingroup$ Thanks for the answers. I'm playing with CountryData, but still not clear on how to approach the problem. It looks I'll have to combine 2 plots, one with the shades on the countries, one with the circles. $\endgroup$ Commented May 13, 2014 at 19:42
  • 2
    $\begingroup$ Please include data sample to your post, it can be made up, does not matter :) The records you've shown do not contain country name in contrary to what you;ve said in the question. $\endgroup$
    – Kuba
    Commented May 13, 2014 at 19:48
  • 1
    $\begingroup$ Moreover, the state acronyms follow the city names in the same record, contrary to how you defined it in the question. Please try to come up with a single, consistent data convention. $\endgroup$ Commented May 13, 2014 at 21:34

3 Answers 3

3
$\begingroup$

This should give you an idea for an approach:

data = {{{"NewYork", "NewYork", "UnitedStates"}, 22}, 
        {{"SanFrancisco", "California", "UnitedStates"}, 13}, 
        {{"Boston", "Massachusetts", "UnitedStates"}, 7}, 
        {{"Arlington", "Massachusetts", "UnitedStates"}, 4}};

Graphics[
 {FaceForm[], EdgeForm[Black],
  CountryData["UnitedStates", "Polygon"],
  PointSize[0.005], Red,
  {Point[#[[1]] // Reverse], Circle[#[[1]] // Reverse, #[[2]]/10]} & /@ 
    ({CityData[#[[1]], "Coordinates"], #[[2]]} & /@ data)
  }
 ]

Mathematica graphics

In V10, this all will be much easier and more beautiful; see GeoGraphics.

$\endgroup$
1
  • $\begingroup$ Thanks for the answer, Sjoerd. Looks nice. I came up with a similar solution, but took me couple of hours and probably you came up with yours in few minutes. I marked your answer as the accepted one, but still haven't figured out what I think is the hardest part, mixing the dot plots (for the records with City and State) with the Shades (for the records with only Country). Any thoughts on that? $\endgroup$ Commented May 14, 2014 at 3:11
3
$\begingroup$

Hope this provides an idea on how to use the functionality. Sorry for the length of the sample data (source forbes.com).

    data = {{"Rank", "Name", "Net Worth", "Age", "Source", 
    "CitizenShip"}, {1., "Bill Gates", 77.7, 58., "Microsoft", 
    "United States"}, {2., "Carlos Slim Helu & family", 72.1, 74., 
    "telecom", "Mexico"}, {3., "Warren Buffett", 65.5, 83., 
    "Berkshire Hathaway", "United States"}, {4., "Amancio Ortega", 
    63.5, 78., "retail", "Spain"}, {5., "Larry Ellison", 51.2, 69., 
    "Oracle", "United States"}, {6., "Charles Koch", 41.1, 78., 
    "diversified", "United States"}, {6., "David Koch", 41.1, 74., 
    "diversified", "United States"}, {8., "Christy Walton & family", 
    38.8, 59., "Wal-Mart", "United States"}, {9., "Sheldon Adelson", 
    37.1, 80., "casinos", "United States"}, {10., "Jim Walton", 36.6, 
    66., "Wal-Mart", "United States"}, {11., "Alice Walton", 36.1, 
    64., "Wal-Mart", "United States"}, {12., "S. Robson Walton", 36.1,
     70., "Wal-Mart", "United States"}, {13., 
    "Bernard Arnault & family", 35.9, 65., "LVMH", "France"}, {14., 
    "Liliane Bettencourt & family", 35.7, 91., "L'Oreal", 
    "France"}, {15., "Li Ka-shing", 34.1, 85., "diversified", 
    "Hong Kong"}, {16., "Michael Bloomberg", 33.1, 72., 
    "Bloomberg LP", "United States"}, {17., "Stefan Persson", 32.2, 
    66., "H&M", "Sweden"}, {18., "Larry Page", 29.5, 41., "Google", 
    "United States"}, {19., "Sergey Brin", 29.1, 40., "Google", 
    "United States"}, {20., "Jeff Bezos", 28.2, 50., "Amazon.com", 
    "United States"}, {21., "Michele Ferrero & family", 26.9, 89., 
    "chocolates", "Italy"}, {22., "Mark Zuckerberg", 26.6, 29., 
    "Facebook", "United States"}, {23., "Karl Albrecht", 25.9, 94., 
    "retail", "Germany"}, {24., "Mukesh Ambani", 24.7, 57., 
    "petrochemicals, oil & gas", "India"}, {25., "Aliko Dangote", 
    24.6, 57., "cement, sugar, flour", "Nigeria"}, {26., 
    "David Thomson & family", 23.6, 56., "media", "Canada"}, {27., 
    "Dieter Schwarz", 23.4, 74., "retail", "Germany"}, {28., 
    "Carl Icahn", 23.4, 78., "investments", "United States"}, {29., 
    "George Soros", 23., 83., "hedge funds", "United States"}, {30., 
    "Jorge Paulo Lemann", 21.6, 74., "beer", "Brazil"}, {31., 
    "Lee Shau Kee", 20.7, 86., "diversified", "Hong Kong"}, {32., 
    "Steve Ballmer", 20.3, 58., "Microsoft", "United States"}, {33., 
    "Prince Alwaleed Bin Talal Alsaud", 20.2, 59., "investments", 
    "Saudi Arabia"}, {34., "Leonardo Del Vecchio", 20.1, 78., 
    "eyeglasses", "Italy"}, {35., "Len Blavatnik", 20.1, 56., 
    "diversified", "United States"}, {36., "Forrest Mars Jr", 19.7, 
    82., "candy", "United States"}, {36., "Jacqueline Mars", 19.7, 
    74., "candy", "United States"}, {36., "John Mars", 19.7, 77., 
    "candy", "United States"}, {39., "Theo Albrecht Jr & family", 
    19.5, 63., "Aldi, Trader Joe's", "Germany"}, {40., 
    "Michael Otto & family", 19.3, 71., "retail, real estate", 
    "Germany"}, {41., "Phil Knight", 18.5, 76., "Nike", 
    "United States"}, {42., "Susanne Klatten", 18.2, 52., 
    "BMW, pharmaceuticals", "Germany"}, {43., "Michael Dell", 18.1, 
    49., "Dell", "United States"}, {44., "Lui Che Woo", 17.9, 84., 
    "casinos", "Hong Kong"}, {45., "Alisher Usmanov", 17.9, 60., 
    "steel & mining, telecom, investments", "Russia"}, {46., 
    "Gina Rinehart", 17.7, 60., "mining", "Australia"}, {47., 
    "Harold Hamm", 17.6, 68., "oil & gas", "United States"}, {48., 
    "Mikhail Fridman", 17.6, 50., "oil, banking, telecom", 
    "Russia"}, {49., "Viktor Vekselberg", 17.5, 57., "metals, energy",
     "Russia"}, {50., "Masayoshi Son", 17.5, 56., "internet, telecom",
     "Japan"}, {51., "Abigail Johnson", 17.3, 52., "money management",
     "United States"}, {52., "Lakshmi Mittal", 16.8, 63., "steel", 
    "India"}, {53., "Joseph Safra", 16.5, 75., "banking", 
    "Brazil"}, {54., "Francois Pinault & family", 16.1, 77., "retail",
     "France"}, {55., "Tadashi Yanai & family", 16.1, 65., "retail", 
    "Japan"}, {56., "Luis Carlos Sarmiento", 16., 81., "banking", 
    "Colombia"}, {57., "Paul Allen", 16., 61., 
    "Microsoft, investments", "United States"}, {58., "Charles Ergen",
     15.8, 61., "Dish Network", "United States"}, {59., 
    "Stefan Quandt", 15.7, 48., "BMW", "Germany"}, {60., 
    "Anne Cox Chambers", 15.5, 94., "media", "United States"}, {61., 
    "Mohammed Al Amoudi", 15.3, 67., "oil, diversified", 
    "Saudi Arabia"}, {62., "Donald Bren", 15.1, 82., "real estate", 
    "United States"}, {63., "Azim Premji", 15.1, 68., "software", 
    "India"}, {64., "Laurene Powell Jobs & family", 14.9, 50., 
    "Apple, Disney", "United States"}, {65., 
    "Serge Dassault & family", 14.9, 89., "aviation", "France"}, {66.,
     "Vladimir Lisin", 14.5, 58., "steel, transport", "Russia"}, {67.,
     "Georg Schaeffler", 14.5, 49., "ball bearings", "Germany"}, {68.,
     "German Larrea Mota Velasco & family", 14.5, 60., "mining", 
    "Mexico"}, {69., "Ray Dalio", 14.4, 64., "hedge funds", 
    "United States"}, {70., "Rupert Murdoch & family", 14.2, 83., 
    "media", "United States"}, {71., "Leonid Mikhelson", 14.2, 58., 
    "gas, chemicals", "Russia"}, {72., "Vladimir Potanin", 14.1, 53., 
    "metals", "Russia"}, {73., "Ronald Perelman", 14.1, 71., 
    "leveraged buyouts", "United States"}, {74., 
    "Iris Fontbona & family", 14.1, 71., "mining", "Chile"}, {75., 
    "Gennady Timchenko", 14., 61., "oil & gas", "Russia"}, {76., 
    "John Fredriksen", 14., 69., "shipping", "Cyprus"}, {77., 
    "Pallonji Mistry", 14., 84., "construction", "Ireland"}, {78., 
    "Wang Jianlin", 13.9, 59., "real estate", "China"}, {79., 
    "Johanna Quandt", 13.6, 87., "BMW", "Germany"}, {80., 
    "John Paulson", 13.5, 58., "hedge funds", "United States"}, {81., 
    "Dilip Shanghvi", 13.3, 58., "pharmaceuticals", "India"}, {82., 
    "Cheng Yu-tung", 13.3, 88., "diversified", "Hong Kong"}, {83., 
    "Gerald Cavendish Grosvenor & family", 13.2, 62., "real estate", 
    "United Kingdom"}, {84., "Lee Kun-Hee", 13.1, 72., 
    "electronics/insurance", "South Korea"}, {85., "Vagit Alekperov", 
    13.1, 63., "Lukoil", "Russia"}, {86., 
    "Thomas & Raymond Kwok & family", 13., "-", "real estate", 
    "Hong Kong"}, {87., "Alejandro Santo Domingo Davila & family", 
    12.8, 37., "beer", "Colombia"}, {88., "Henry Sy & family", 12.7, 
    89., "diversified", "Philippines"}, {89., "Jack Taylor & family", 
    12.7, 91., "Enterprise Rent-A-Car", "United States"}, {90., 
    "Ma Huateng", 12.6, 42., "internet media", "China"}, {91., 
    "James Simons", 12.5, 76., "hedge funds", "United States"}, {92., 
    "Ernesto Bertarelli & family", 12.1, 48., "biotech, investments", 
    "Switzerland"}, {93., "Hans Rausing", 12., 88., "packaging", 
    "Sweden"}, {94., "Alberto Bailleres Gonzalez & family", 12., 82., 
    "mining", "Mexico"}, {95., "Rinat Akhmetov", 11.9, 47., 
    "steel, coal", "Ukraine"}, {96., "Ananda Krishnan", 11.9, 76., 
    "telecom", "Malaysia"}, {97., "David & Simon Reuben", 11.8, 71., 
    "investments, real estate", "United Kingdom"}, {98., 
    "Robert & Philip Ng", 11.7, "-", "real estate", 
    "Singapore"}, {99., "Robert Kuok", 11.6, 90., "diversified", 
    "Malaysia"}, {100., "Zong Qinghou", 11.4, 68., "beverages", 
    "China"}, {101., "Robin Li", 11.3, 45., "internet search", 
    "China"}, {102., "Dhanin Chearavanont & family", 11.3, 75., 
    "food", "Thailand"}, {103., "German Khan", 11.3, 52., 
    "oil, banking, telecom", "Russia"}, {104., "Andrey Melnichenko", 
    11.2, 42., "coal, fertilizers", "Russia"}, {105., 
    "Charlene de Carvalho-Heineken", 11.2, 59., "Heineken", 
    "Netherlands"}, {106., "Marcel Herrmann Telles", 11.2, 64., 
    "beer", "Brazil"}, {107., "Petr Kellner", 11.2, 49., 
    "banking, insurance", "Czech Republic"}, {108., "Hansjoerg Wyss", 
    11.2, 79., "medical devices", "Switzerland"}, {109., "Shiv Nadar",
     11.1, 68., "information technology", "India"}, {110., 
    "Steve Cohen", 11.1, 58., "hedge funds", "United States"}, {111., 
    "Andrew Beal", 11., 61., "banks, real estate", 
    "United States"}, {112., "Stefano Pessina", 10.9, 72., 
    "drugstores", "Italy"}, {113., "Hinduja Brothers", 10.9, "-", 
    "diversified", "United Kingdom"}, {114., 
    "Carrie Perrodo & family", 10.8, 63., "Inherited", 
    "France"}, {115., "Tsai Eng-Meng", 10.7, 57., "food, beverages", 
    "Taiwan"}, {116., "Mikhail Prokhorov", 10.7, 49., "investments", 
    "Russia"}, {117., "Kjeld Kirk Kristiansen", 10.6, 66., "Lego", 
    "Denmark"}, {118., "Alexey Mordashov", 10.5, 48., 
    "steel, investments", "Russia"}, {119., "Miuccia Prada", 10.4, 
    65., "Prada", "Italy"}, {120., "Giorgio Armani", 10.3, 79., 
    "fashion", "Italy"}, {121., "Klaus-Michael Kuehne", 10.3, 76., 
    "shipping", "Germany"}, {122., "Philip Anschutz", 10.2, 74., 
    "investments", "United States"}, {123., "Roberto Irineu Marinho", 
    10., 66., "media", "Brazil"}, {124., "George Kaiser", 10., 71., 
    "oil & gas, banking", "United States"}, {125., "David Tepper", 
    10., 56., "hedge funds", "United States"}, {126., "Xavier Niel", 
    9.9, 46., "internet, telecom", "France"}, {127., 
    "Charles Butt & family", 9.9, 76., "supermarkets", 
    "United States"}, {128., "Patrick Soon-Shiong", 9.8, 62., 
    "pharmaceuticals", "United States"}, {129., 
    "Charoen Sirivadhanabhakdi", 9.8, 70., "beverages", 
    "Thailand"}, {130., "Carlos Alberto Sicupira", 9.7, 66., "beer", 
    "Brazil"}, {131., "Stephen Schwarzman", 9.7, 67., 
    "private equity", "United States"}, {132., "Joao Roberto Marinho",
     9.6, 60., "media", "Brazil"}, {132., "Jose Roberto Marinho", 9.6,
     58., "media", "Brazil"}, {134., "Sergei Galitsky", 9.6, 46., 
    "retail", "Russia"}, {135., "Roman Abramovich", 9.5, 47., 
    "steel, investments", "Russia"}, {136., "Patrick Drahi", 9.4, 50.,
     "Telecom", "France"}, {137., "Dietrich Mateschitz", 9.4, 69., 
    "Red Bull", "Austria"}, {138., "Edward Johnson III", 9.4, 83., 
    "money management", "United States"}, {139., "Richard Kinder", 
    9.2, 69., "pipelines", "United States"}, {140., 
    "Galen Weston & family", 9.2, 73., "retail", "Canada"}, {141., 
    "Elaine Marshall & family", 9.1, 71., "diversified", 
    "United States"}, {142., "Alain Wertheimer", 9.1, 65., "Chanel", 
    "France"}, {142., "Gerard Wertheimer", 9.1, 63., "Chanel", 
    "France"}, {144., "Joseph Lau", 9., 62., "real estate", 
    "Hong Kong"}, {145., "Vincent Bollore", 9., 62., "investments", 
    "France"}, {146., "Ludwig Merckle", 8.9, 49., "pharmaceuticals", 
    "Germany"}, {147., "Silvio Berlusconi & family", 8.9, 77., 
    "media", "Italy"}, {148., "Dmitry Rybolovlev", 8.8, 47., 
    "fertilizer", "Russia"}, {149., "Michael Kadoorie & family", 8.8, 
    72., "diversified", "Hong Kong"}, {150., "Thomas Peterffy", 8.8, 
    69., "discount brokerage", "United States"}, {151., 
    "Alexei Kuzmichev", 8.8, 51., "oil, banking, telecom", 
    "Russia"}, {152., "Samuel Newhouse Jr", 8.8, 86., "media", 
    "United States"}, {153., "Margarita Louis-Dreyfus", 8.7, 51., 
    "commodities", "Switzerland"}, {154., "Eric Schmidt", 8.7, 59., 
    "Google", "United States"}, {155., "Hasso Plattner", 8.7, 70., 
    "software", "Germany"}, {156., "Antonia Johnson", 8.6, 70., 
    "diversified", "Sweden"}, {157., "R. Budi Hartono", 8.6, 73., 
    "banking, tobacco", "Indonesia"}, {158., "Jack Ma", 8.5, 49., 
    "e-commerce", "China"}, {159., "Reinhold Wuerth", 8.5, 79., 
    "fasteners", "Germany"}, {160., "August von Finck", 8.4, 84., 
    "Investments", "Germany"}};
data[[All, 6]] = StringReplace[data[[All, 6]], " " -> ""];

fields = First@data; data = Rest@data;

countries = Union@data[[All, 6]];

worthbyCountry = {#, Total[Cases[data, {_, _, w_, _, _, #} -> w]]} & /@
    countries;

scale = {Min[#], Max[#]} &@Log@worthbyCountry[[All, 2]];

wikiSearch[term_] := 
 Module[{search}, search = StringReplace[term, " " -> "+"]; 
  Hyperlink[term, 
   "http://www.wikipedia.org/search-redirect.php?family=wikipedia&\
search=" ~~ search ~~ "&language=en&go=++\[RightArrow]++&go=Go"]]

retrievePeople[country_] := 
 Column[{Style[country, FontSize -> 18, Bold], 
    Grid[Join[{Drop[fields, -1]}, 
      Cases[data, {rank_, name_, w_, age_, sector_, country} -> {rank,
          wikiSearch@name, w, age, sector}]], Frame -> All]}, 
   Center] // Quiet

Graphics[{If[MemberQ[countries, #], 
     ColorData["DarkRainbow"][
      Rescale[Log@
        worthbyCountry[[Position[worthbyCountry[[All, 1]], #][[1]], 
           2]][[1]], scale]], LightBrown], 
    PopupWindow[Tooltip[CountryData[#, "SchematicPolygon"], #], 
     retrievePeople[#]]} & /@ CountryData[], ImageSize -> Large]

enter image description here

$\endgroup$
2
  • $\begingroup$ Thanks for the example and for taking the time to even show the animation of how it would work. It gives me some functions to explore. Still haven't figured out what I think is the hardest part, mixing the dot plots (for the records with City and State) with the Shades (for the records with only Country). Any thoughts on how to achieve that? $\endgroup$ Commented May 14, 2014 at 20:45
  • $\begingroup$ Hola @JuanCarlosMéndez, it would be quite straightforward by just adding the Disk section mentioned in the other answers after the polygon drawing function. I would also recommend that you take a look at the excellent presentation from Brett Champion (Data Visualization Quick Start) that you can find here. wolfram.com/training/special-event/… $\endgroup$
    – Zviovich
    Commented May 15, 2014 at 18:41
1
$\begingroup$

This is what I have developed so far, very similar to what Sjoerd wrote on the accepted answer. I'm splitting the problem, trying to solve first the part of the dots, when I have available State and City. Later on, I'll work on the shades on the countries, for the records with only Country and nothing else.

a = {{{"New York ", "NY"}, 10}, {{"San Francisco ", "CA"}, 
8}, {{"Boston  ", "MA"}, 4}, {{"Arlington ", "MA"}, 
2}, {{"Arlington ", "VA"}, 1}, {{"Cambridge ", "MA"}, 
1}, {{"Needham ", "MA"}, 1}, {{"Acton ", "MA"}, 
1}, {{"Brooklyn  ", "NY"}, 1}, {{"Los Altos ", "CA"}, 
1}, {{"Miami ", "FL"}, 1}}

With that data, the following gets me close.

Graphics[{Gray, CountryData["UnitedStates", "Polygon"], 
Opacity[0.3, Blue], 
Cases[Disk[Reverse[CityData[First[#], "Coordinates"]], 
  0.09*Last[#]] & /@ a, Disk[{__Real}, _Real]]}]

The result is

enter image description here

Now, the next is to deal with something like

a = {{{"","","India"},25},{{"","","China"},22},{{"New York ", "NY", "United States"},
10}, {{"San Francisco ", "CA", "United States"}, 
8}, {{"Boston  ", "MA", "United States"}, 4}, {{"Arlington", "MA", "United States"}, 
2}, {{"Arlington", "VA", "United States"}, 1}, {{"Cambridge", "MA", "United States"}, 
1}, {{"Needham", "MA", "United States"}, 1}, {{"Acton", "MA", "United States"}, 
1}, {{"Brooklyn", "NY", "United States"}, 1}, {{"Los Altos", "CA", "United States"}, 
1}, {{"Miami", "FL", "United States"}, 1}}
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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