cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
JMP is taking Discovery online, April 16 and 18. Register today and join us for interactive sessions featuring popular presentation topics, networking, and discussions with the experts.
Choose Language Hide Translation Bar
SDF1
Super User

How to get Legend Box information, like color and marker type

Dear JMP Community,

 

  (W10 Enterprise 64-bit, JMP Pro 15.0)

 

  I have a user that is using graph builder to generate a rather complex graph containing multiple bits of information. The market data is split by region, customer, etc. As a result, the scatter plot is color coded as well as having multiple markers. As an example, below is something kind of like what the graph might look like (using Big Class Families.jmp).

DS_0-1584543309277.png

 

  What I'd like to do is take his original graph builder plots and extract from the legend the marker style and color and set those as dt properties. The purpose is so the user can run a bit of JSL code as a hot button in their toolbar that will fix the markers and colors for the data. Reason this is needed is that from within Graph Builder, whenever the user uses the Data Filter to change regions, the color coding and markers change for the set of customers because the number of customers changes within each region. They'd like to have this as a fixed property of the data column for example.

 

  I was trying a bit of JSL code like this in an attempt to get the information from the LegendBox(1) within the tree structure, but I get null as the result of the line: test = legend<<Get Property();

Names Default to here(1);

dt = Open("$Sample_Data/Big Class Families.jmp");

gb=dt<<Graph Builder(
	Size( 528, 456 ),
	Show Control Panel( 0 ),
	Graph Spacing( 5 ),
	Variables( X( :weight ), Y( :height ), Overlay( :age ), Color( :sex ) ),
	Elements( Points( X, Y, Legend( 33 ) ) )
);

gb<<show tree structure; //just used for debugging, won't be in final code.

lgnd= (gb<<Report)[LegendBox(1)];

test = legend<<Get Property();

  If the information of color is in RGB or whatever, that's fine, it doesn't need to be a name like "blue" or "red".

 

  Any suggestions on how to proceed are much appreciated.

 

Thanks,

DS

1 ACCEPTED SOLUTION

Accepted Solutions
MJE
MJE
Level III

Re: How to get Legend Box information, like color and marker type

Maybe this part here might help you. At least, it provides you with some information which actual data point in the graph has which colour and marker. Unfortunately, I couldn't figure out a way to directly correlate the data points (resp. the marker seg) to the actual row numbers. Maybe someone else has an idea on how to do that...

 

The "get marker" message can be replaced by "get markers" to give you a list of used markers within this marker seg. But as they are all the same in this state, I cut it short for better readability.

 

Names Default To Here( 1 );

dt = Open( "$Sample_Data/Big Class Families.jmp" );

gb = dt << Graph Builder(
	Size( 528, 456 ),
	Show Control Panel( 0 ),
	Graph Spacing( 5 ),
	Variables( X( :weight ), Y( :height ), Overlay( :age ), Color( :sex ) ),
	Elements( Points( X, Y, Legend( 33 ) ) ),
	MarkerSeg(:weight, :height)
);


//gb << show tree structure;//only for debugging and building the script


segs =  Report( gb )[Framebox( 1 )] << Find Segs;

For ( i = 1, i <= n items (segs), i++,

seg = Report( gb )[Framebox( 1 )] << Find Seg( MarkerSeg(i) );

nx = seg << get x values;
ny = seg << get y values;
m = seg << get marker;
c = seg << get colors;


show (nx, ny, m, c);
);

Hope this helps.

 

br

Malte

View solution in original post

4 REPLIES 4
MJE
MJE
Level III

Re: How to get Legend Box information, like color and marker type

Hi @SDF1 ,

 

if I understood your issue correctly, you might want to check into the row states.

<< copy from row states

and

<< copy to row states

allows you to transfer row state information (such as color, marker, etc.) into a seperate column and back again into the row states (examples and syntax can be found in the scripting index).

 

br

Malte

SDF1
Super User

Re: How to get Legend Box information, like color and marker type

Hi @MJE,

 

  Thanks for the feedback. Unfortunately, it's not quite what I'm interested in doing. The user hasn't actually changed the row state or marker, they're letting Graph Builder do that automatically. But each time a change is made, the colors and markers change according to JMP's defaults. I want to extract the marker and color "settings" that Graph Builder does automatically and then apply that to the dt so it's fixed and doesn't get updated when a change is made to Graph Builder. I want to do this automatically for ease to the user.

 

  I think it's something closer to the MarkerSeg and <<GetColors or <<GetMarkers, but I'm not familiar with how to implement those.

 

  I'm doing some reading on it now and trying to modify the examples in the Scripting Index, using the modified code below.

Names Default To Here( 1 );

dt = Open( "$Sample_Data/Big Class Families.jmp" );

gb = dt << Graph Builder(
	Size( 528, 456 ),
	Show Control Panel( 0 ),
	Graph Spacing( 5 ),
	Variables( X( :weight ), Y( :height ), Overlay( :age ), Color( :sex ) ),
	Elements( Points( X, Y, Legend( 33 ) ) ),
	MarkerSeg(:weight, :height, Row States(dt))
);

gb << show tree structure;//only for debugging and building the script

lgnd = (gb << Report)[FrameBox(1)];

markerseg = (lgnd<<Find Seg(MarkerSeg(1)));

markerseg <<Get Markers;

  But, when I run it, I get the following output for markerseg: {"Dot", "Dot", "Dot", "Dot", "Dot", "Dot", "Dot", "Dot"}

 

  From the graphic I included in the original post, each data point is NOT a "Dot".

 

Thanks!,

DS

MJE
MJE
Level III

Re: How to get Legend Box information, like color and marker type

Maybe this part here might help you. At least, it provides you with some information which actual data point in the graph has which colour and marker. Unfortunately, I couldn't figure out a way to directly correlate the data points (resp. the marker seg) to the actual row numbers. Maybe someone else has an idea on how to do that...

 

The "get marker" message can be replaced by "get markers" to give you a list of used markers within this marker seg. But as they are all the same in this state, I cut it short for better readability.

 

Names Default To Here( 1 );

dt = Open( "$Sample_Data/Big Class Families.jmp" );

gb = dt << Graph Builder(
	Size( 528, 456 ),
	Show Control Panel( 0 ),
	Graph Spacing( 5 ),
	Variables( X( :weight ), Y( :height ), Overlay( :age ), Color( :sex ) ),
	Elements( Points( X, Y, Legend( 33 ) ) ),
	MarkerSeg(:weight, :height)
);


//gb << show tree structure;//only for debugging and building the script


segs =  Report( gb )[Framebox( 1 )] << Find Segs;

For ( i = 1, i <= n items (segs), i++,

seg = Report( gb )[Framebox( 1 )] << Find Seg( MarkerSeg(i) );

nx = seg << get x values;
ny = seg << get y values;
m = seg << get marker;
c = seg << get colors;


show (nx, ny, m, c);
);

Hope this helps.

 

br

Malte

SDF1
Super User

Re: How to get Legend Box information, like color and marker type

Hi @MJE,

 

  Thanks for the additional feedback. It works! Thanks for the solution, I'll mark it as such. I did modify it just slightly to be more like what the user is asking for, but otherwise, it does the job. From what I can tell, the list of markers and colors are in the same order as the legend.

 

Here's the modified version of your code I used:

Names Default To Here( 1 );

dt = Open( "$Sample_Data/Big Class Families.jmp" );

gb = dt << Graph Builder(
	Size( 528, 456 ),
	Show Control Panel( 0 ),
	Graph Spacing( 5 ),
	Variables( X( :weight ), Y( :height ), Overlay( :age ), Color( :age ) ),
	Elements( Points( X, Y, Legend( 33 ) ) ),
	MarkerSeg(:weight, :height)
);

segs = Report(gb)[Framebox(1)]<<Find Segs;

MarkerList = {};
ColorList = {};
For(i=1, i<=Nitems(segs),i++,
	seg = Report(gb)[Framebox(1)]<<Find Seg(MarkerSeg(i));
	m = seg<<get Marker;
	Insert Into (MarkerList,m);
	c = seg << get colors;
	Insert Into(ColorList,EvalList({c[1]}));
);

Show(MarkerList, ColorList);

And the output I get:

MarkerList = {"Circle", "Plus", "Diamond", "X", "Triangle", "Y"};
ColorList = {{66, 112, 221}, {212, 73, 88}, {61, 174, 70}, {162, 43, 221}, {204, 121, 41}, {40, 182, 143}};

 

DS_0-1584636378890.png

Thanks!,

DS