Message Boards Message Boards

0
|
4145 Views
|
5 Replies
|
3 Total Likes
View groups...
Share
Share this post:

Create a BubbleChart with data in fours?

Posted 7 years ago

I would like to use BubbleChart for data in the form of {{4,1,3,7},{0,9,1,1},...}. I would like the color of each bubble to indicate the fourth data piece. For instance, the data above would produce two bubbles, one at (4,3) with a radius relative to 3 and a color relative to 7, and the other bubble at (0,9) with a smaller radius and a color closer to 0 on a gradient.

The docs include a section in BubbleChart subtitled "Use metadata passed on from the input, in this case charting the data" that seems to indicate that this sort of thing is possible. However, I can't seem to figure out what is going on in this example. The doc example works, but unless I can figure it out, I can't bend it to my own purpose. Here is what the docs have:

DataDrilldownBubble[{{xmin_, xmax_}, {ymin_, ymax_}}, v_, {meta_}, style___] := PopupWindow[Polygon[{{xmin, ymin}, {xmax, ymax}, {xmin, ymax}, {xmax, ymin}}], PieChart[meta]];
DataDrilldownBubble[{{xmin_, xmax_}, {ymin_, ymax_}}, y_, ___] := Rectangle[{xmin, ymin}, {xmax, ymax}];
BubbleChart[{{1, 0, 1} -> Range[5], {0, 1, 2}, {1, 2, 3} -> RandomReal[1, 10]}, ChartElementFunction -> DataDrilldownBubble]

Can anyone please explain to me what is going on in this example, or possibly suggest how I might accomplish my goal?

Thanks in advance,

Mark Greenberg

POSTED BY: Mark Greenberg
5 Replies
Posted 7 years ago

Thanks, Sander. When I said that your solution worked perfectly, I had only tried the example you sent, which did appear to do what I want. I have now tested your corrected solution with my data and it does what I want it to do. Where can I find out more about this technique of using "metadata"? I cannot find a reference to it in the docs.

Mark

POSTED BY: Mark Greenberg

I mean my solutions are equivalent indeed. It was just by the example i found in the documentation that I figured it out; it is a bit sparsely documented... Metadata can be anything, even multiple things, so I guess you can make now your own function...

POSTED BY: Sander Huisman
POSTED BY: Sander Huisman
Posted 7 years ago
POSTED BY: Mark Greenberg

Hi Mark,

I think I spoke too soon; it IS parsed:

BubbleChart[{{1, 0, 1} -> Range[5], {0, 1, 2}, {1, 2, 3} -> RandomReal[1, 10]}, 
ChartElementFunction -> ((Print[{##}]; DataDrilldownBubble[{##}]) &)] 

Notice I put ## in there, it is parsed as multiple arguments not as a list of arguments; that was my mistake... I found out by checking out the code:

Needs["GeneralUtilities`"]
PrintDefinitions@Charting`iBubbleChart

and the dependencies.

So you can do it like this:

data = {{4, 1, 3} -> 7, {0, 9, 1} -> 1, {4, 5, 2} -> 5, {2, 3, 0.4`} -> 2};
data[[All, 2]] = Rescale[data[[All, 2]]];
ClearAll[g]
g[{xrange_, yrange_}, {x_, y_, z_}, meta_] := Style[Disk[{x, y}, z], ColorData["Rainbow"][First@meta]]
BubbleChart[data, ChartElementFunction -> g, AspectRatio -> Automatic]
POSTED BY: Sander Huisman
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