Message Boards Message Boards

0
|
4010 Views
|
1 Reply
|
0 Total Likes
View groups...
Share
Share this post:

How does GroupBy work with an expanded list.

Posted 10 years ago

I started with a list that looks like

data={Industry_String,{ XCoord_,YCoord_Real}}

So when I did a GroupBy for each industry it looks like: byIndust = GroupBy[data, First, Point[Map[GeoPosition, #[[All, 2]]]] &];

This groups by each industry and puts the Point and GeoPositon around each Gps pair so I can map them.

Now I need to add a tooltip that will display the customer when you mouse over the gps point. My list now looks like:

data={Industry_String,{XCoord_Real,YCoord_Real},Customer_String}}

My question is when I do the GroupBy with #[[All,2;;3] it won't wrap the customer string in the Point and GeoPosition code, so I need to put it outside that. What should the structure of the GroupBy look like with another field that I want in the output.

POSTED BY: Buck Huffman

Generate some data

In[18]:= Clear[data]
data = With[{oo = 30}, 
  Table[{"Corp_" <> ToString[RandomInteger[{1, 10}]], {44., 7.} + 
     RandomReal[{0, 1}, 2], 
    "Cust_" <> ToString[RandomInteger[{1, 5}]]}, {oo}]
  ]

Out[19]= {{"Corp_9", {44.5789, 7.49415}, "Cust_2"}, {"Corp_7", {44.6927, 7.89368}, "Cust_1"}, 
          {"Corp_4", {44.6963, 7.0182}, "Cust_1"}, {"Corp_3", {44.757, 7.15789}, "Cust_3"}, 
          {"Corp_1", {44.9661, 7.89726}, "Cust_5"}, {"Corp_3", {44.4224, 7.244}, "Cust_4"}, 
          {"Corp_8", {44.5074, 7.65182}, "Cust_2"}, {"Corp_9", {44.688, 7.50798}, "Cust_1"}, 
          {"Corp_5", {44.8365, 7.82396}, "Cust_5"}, {"Corp_6", {44.168, 7.63074}, "Cust_5"}, 
          {"Corp_7", {44.7713, 7.63471}, "Cust_1"}, {"Corp_7", {44.6458, 7.80952}, "Cust_3"}, 
          {"Corp_10", {44.7562, 7.79829}, "Cust_2"}, {"Corp_1", {44.2319, 7.16698}, "Cust_1"}, 
          {"Corp_4", {44.9039, 7.59623}, "Cust_3"}, {"Corp_4", {44.7848, 7.82588}, "Cust_2"}, 
          {"Corp_8", {44.3374, 7.01723}, "Cust_3"}, {"Corp_8", {44.3942, 7.75292}, "Cust_3"}, 
          {"Corp_1", {44.2185, 7.78818}, "Cust_2"}, {"Corp_4", {44.0674, 7.70929}, "Cust_2"},
          {"Corp_3", {44.805, 7.96758},  "Cust_5"}, {"Corp_7", {44.7443, 7.48924}, "Cust_3"}, 
          {"Corp_2", {44.9583, 7.65115}, "Cust_3"}, {"Corp_10", {44.7586, 7.89361}, "Cust_2"}, 
          {"Corp_6", {44.6307, 7.83403}, "Cust_3"}, {"Corp_1", {44.6629, 7.98558},  "Cust_1"}, 
          {"Corp_9", {44.2756, 7.5442},  "Cust_4"}, {"Corp_8", {44.6013, 7.21996}, "Cust_4"}, 
          {"Corp_1", {44.2727, 7.97379}, "Cust_4"}, {"Corp_8", {44.4211, 7.26044}, "Cust_2"}}

define a function

Clear[buckHuff]
buckHuff[l_List] := Tooltip[Point[GeoPosition[#[[2]]]], Last[#]] & /@ l

and use it

In[27]:= GroupBy[data, First, buckHuff]

if you mouse over the output the customer is shown as tool tip.

POSTED BY: Udo Krause
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract