cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Check out the JMP® Marketplace featured Capability Explorer add-in
Choose Language Hide Translation Bar
Jemster
Level III

Add Vertical Lines to Histogram

I have built a histogram using graph builder and would like to adapt my script to add vertical lines at a value of my choosing overlayed on the histogram.

2 ACCEPTED SOLUTIONS

Accepted Solutions
jthi
Super User

Re: Add Vertical Lines to Histogram

Here are couple of options. First one is first letting JMP script it for you and then using Insert one expression into another using Eval Insert, Eval Expr, Parse, and Substitute and second one is modified from Scripting Index example found by searching for Ref Line

Names Default To Here(1);
dt = Open("$SAMPLE_DATA/Big Class.jmp");
ref_line = 180;

// Option1
Eval(EvalExpr(gb1 = dt << Graph Builder(
	Size(529, 457),
	Show Control Panel(0),
	Variables(X(:weight)),
	Elements(Histogram(X, Legend(3))),
	SendToReport(
		Dispatch(
			{},
			"weight",
			ScaleBox,
			{Min(57), Max(205.037037037037), Inc(20), Minor Ticks(0),
			Add Ref Line(Expr(ref_line), "Solid", "Black", "", 1)}
		)
	)
)));

// Option2
gb2 = dt << Graph Builder(
	Size(529, 457),
	Show Control Panel(0),
	Variables(X(:weight)),
	Elements(Histogram(X, Legend(3)))
);
axisbox = Report(gb2)[AxisBox(1)];
axisbox << Add Ref Line(ref_line, "Dotted", red, "F mean", 2);
-Jarmo

View solution in original post

Georg
Level VII

Re: Add Vertical Lines to Histogram

Another option maybe to add a column property spec limit, and let it show in the histogram of distribution platform.

The value can then be used for other platforms as well (process capability ...).

 

Georg_0-1658263242333.png

 

Georg

View solution in original post

5 REPLIES 5
jthi
Super User

Re: Add Vertical Lines to Histogram

Here are couple of options. First one is first letting JMP script it for you and then using Insert one expression into another using Eval Insert, Eval Expr, Parse, and Substitute and second one is modified from Scripting Index example found by searching for Ref Line

Names Default To Here(1);
dt = Open("$SAMPLE_DATA/Big Class.jmp");
ref_line = 180;

// Option1
Eval(EvalExpr(gb1 = dt << Graph Builder(
	Size(529, 457),
	Show Control Panel(0),
	Variables(X(:weight)),
	Elements(Histogram(X, Legend(3))),
	SendToReport(
		Dispatch(
			{},
			"weight",
			ScaleBox,
			{Min(57), Max(205.037037037037), Inc(20), Minor Ticks(0),
			Add Ref Line(Expr(ref_line), "Solid", "Black", "", 1)}
		)
	)
)));

// Option2
gb2 = dt << Graph Builder(
	Size(529, 457),
	Show Control Panel(0),
	Variables(X(:weight)),
	Elements(Histogram(X, Legend(3)))
);
axisbox = Report(gb2)[AxisBox(1)];
axisbox << Add Ref Line(ref_line, "Dotted", red, "F mean", 2);
-Jarmo
mikedriscoll
Level VI

Re: Add Vertical Lines to Histogram

This is tangentially related but I'll put it here anyway.  It's related to the Distribution platform specifically (not graph builder which was in the original question), but may apply to other platforms depending on user preferences, I'm not sure.  I would not expect to be an issue in graph builder, mostly because I don't think user preferences come into play as much.

 

In the distribution platform, if you don't have the probability, density, and show counts axes set to be displayed, then the index for the axis box of the distribution's data is 1, meaning you can reference it with report(xxxx)[AxisBox(1)], similar to Jarmo's post above.  But if you add any of the other axes, the index becomes 2, 3 or 4 (the max of the total axes displayed. if you always have the same settings, you can hard code it and it should be fine. But if the script is deployed widely, you need to account for other user preference settings. I tried doing a 'get items' but I think it always returned 4 even though some were empty. I probably could have found a workaround there, but ended up using xpath.  You can look at the xml, or look at the properties of an output report to see what might work. Meaning, don't just look for an axis box as there could be 4 of them, rather look for the axis box in a border box in a drop box, which appears to be unique to the 'main' axis. Hopefully this stands the test of time, but it's worked for me so far.

 

myrpt = current report();
//show( myrpt<<get XML());
xpList = myrpt << XPath("//DropBox/BorderBox/AxisBox"); // returns a list of matching occurrences
// use xpList[1] instead of referencing an axisbox index.  
// If there's multiple distributions in the report, loop through or be more specific when grabbing the xpath.

 

jthi
Super User

Re: Add Vertical Lines to Histogram

Sometimes these have to be built a bit case by case. Usually I use XPath with some combination of << child, << sib, << parent and so on...

Names Default To Here(1);

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

dist = dt << Distribution(
	Stack(1),
	Continuous Distribution(
		Column(:height),
		Horizontal Layout(1),
		Vertical(0),
		Prob Axis(1),
		Quantile Box Plot(1),
		Normal Quantile Plot(1)
	)
);

axisbox = (Report(dist) << XPath("//ScaleBox"))[1];
axisbox << Add Ref Line(55, "Dotted", red, "F mean", 2);

dist = dt << Distribution(
	Stack(1),
	Continuous Distribution(
		Column(:height),
		Horizontal Layout(1),
		Vertical(0),
		Quantile Box Plot(1),
		Normal Quantile Plot(1)
	)
);

axisbox = (Report(dist) << XPath("//ScaleBox"))[1];
axisbox << Add Ref Line(55, "Dotted", red, "F mean", 2);

dist = dt << Distribution(
	Stack(1),
	Continuous Distribution(
		Column(:height),
		Horizontal Layout(1),
		Vertical(0),
		Count Axis(1),
		Prob Axis(1),
		Density Axis(1),
		Quantile Box Plot(1),
		Normal Quantile Plot(1)
	)
);

axisbox = (Report(dist) << XPath("//ScaleBox"))[1];
axisbox << Add Ref Line(55, "Dotted", red, "F mean", 2);

One option is also to remove the effect of users preferences, but depending on the platform this might take a lot of effort to set all default values to 1 or 0.

-Jarmo
mikedriscoll
Level VI

Re: Add Vertical Lines to Histogram

>>One option is also to remove the effect of users preferences, but depending on the platform this might take a lot of effort to set all default values to 1 or 0.

 

yes, I agree. I thought of doing something like that for some scripts, but actually the particular script this example code came from is designed to loop through all distributions in the output window and make the histogram bins smaller to make it look more 'normal'. Just a generic one-button script that isn't actually building any output, just modifying the axes. 

Georg
Level VII

Re: Add Vertical Lines to Histogram

Another option maybe to add a column property spec limit, and let it show in the histogram of distribution platform.

The value can then be used for other platforms as well (process capability ...).

 

Georg_0-1658263242333.png

 

Georg