キャンセル
次の結果を表示 
表示  限定  | 次の代わりに検索 
もしかして: 

Discussions

Solve problems, and share tips and tricks with other JMP users.
言語を選択 翻訳バーを非表示
YotamS1
Level I

Create multiple charts with different reference lines

Hi,

I would like to accomplish the following task using JSL code:

I have an example file (attached) with 4 columns: date (numeric), y_val (numeric), limit (numeric), group (character).

The "group" column contains 3 distinct values: A,B,C

Each group has a unique value in "limit" column. For example, all group A rows have a value of 67 in the "limit" column.

 

The task:

1. I would like to create 3 charts (one for each group), each of them in different tab.

2. The tabs names should be according to groups. So A,B,C.

3. Each chart (Y by X) should have "date" in X axis, "y_val" in Y axis, and value of "limit" as a reference line on the y axis (that matches the specific group).

 

I have attached an example data table, as well as simple JSL script that gives the output I want.

However, the code has 3 drawbacks:

1. I specified the reference line values manually, instead of reading them from "limit" column.

2. I named the tabs "A","B","C" manually, instead of reading them from "group" column.

3. I manually created 3 tabs, instead of automatically counting how many tabs I need (according to the number of distinct values in "group" column).

I would like the solution to address the drawbacks above, as it should generalize for any number of groups (for example A-Z, which means 26 groups and 26 different values for reference lines).

 

Any help would be appreciated.

Thanks

  

1 件の受理された解決策

受理された解決策
jthi
Super User

Re: Create multiple charts with different reference lines

How did you modify For Each? It should be changed to something like

For(idx = 1, idx <= N Items(groups), idx++,
	group = groups[idx];

Full script

詳細を表示...
Names Default To Here(1);

dt = Open("$DOWNLOADS/example.jmp");

// get groups and limits
Summarize(dt, groups = By(:group), limits = Min(:limit));

nw = New Window("Trends", << journal,
	tb = Tab Box()
);

//For Each({group, idx}, groups,
For(idx = 1, idx <= N Items(groups), idx++,
	group = groups[idx];
	biv_expr = EvalExpr(
		temp_biv = dt << Bivariate(
			Y( :y_val ),
			X( :date ),
			Automatic Recalc( 1 ),
			Where(:group == Expr(group))
		);
		rbiv = temp_biv << report;
		axisbox = rbiv[axis box(1)];
		axisbox << Add Ref Line(
			limits[idx], "Solid", "Black", "", 1
		);
	);
	tb << Add(group, V List Box(biv_expr));
);

tb << Set Selected(1);
-Jarmo

元の投稿で解決策を見る

4件の返信4
jthi
Super User

Re: Create multiple charts with different reference lines

Below is one possible example script. If you don't have JMP16+ you will have to change For Each to For loop.

Names Default To Here(1);

dt = Open("$DOWNLOADS/example.jmp");

// get groups and limits
Summarize(dt, groups = By(:group), limits = Min(:limit));

nw = New Window("Trends", << journal,
	tb = Tab Box()
);

For Each({group, idx}, groups,
	biv_expr = EvalExpr(
		temp_biv = dt << Bivariate(
			Y( :y_val ),
			X( :date ),
			Automatic Recalc( 1 ),
			Where(:group == Expr(group))
		);
		rbiv = temp_biv << report;
		axisbox = rbiv[axis box(1)];
		axisbox << Add Ref Line(
			limits[idx], "Solid", "Black", "", 1
		);
	);
	tb << Add(group, V List Box(biv_expr));
);

tb << Set Selected(1);
-Jarmo
YotamS1
Level I

Re: Create multiple charts with different reference lines

Thank you for the quick response!

I have JMP 14.

I copied your script and changed the "For Each" to "For", but got an empty window after running (no error messages).

Maybe there's something else that needs to be changed?

jthi
Super User

Re: Create multiple charts with different reference lines

How did you modify For Each? It should be changed to something like

For(idx = 1, idx <= N Items(groups), idx++,
	group = groups[idx];

Full script

詳細を表示...
Names Default To Here(1);

dt = Open("$DOWNLOADS/example.jmp");

// get groups and limits
Summarize(dt, groups = By(:group), limits = Min(:limit));

nw = New Window("Trends", << journal,
	tb = Tab Box()
);

//For Each({group, idx}, groups,
For(idx = 1, idx <= N Items(groups), idx++,
	group = groups[idx];
	biv_expr = EvalExpr(
		temp_biv = dt << Bivariate(
			Y( :y_val ),
			X( :date ),
			Automatic Recalc( 1 ),
			Where(:group == Expr(group))
		);
		rbiv = temp_biv << report;
		axisbox = rbiv[axis box(1)];
		axisbox << Add Ref Line(
			limits[idx], "Solid", "Black", "", 1
		);
	);
	tb << Add(group, V List Box(biv_expr));
);

tb << Set Selected(1);
-Jarmo
YotamS1
Level I

Re: Create multiple charts with different reference lines

Great, now it works!

Thanks a lot!

おすすめの記事