cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
  • JMP 19 is here! See the new features at jmp.com/new.
  • Register to attend Discovery Summit 2025 Online: Early Users Edition, Sept. 24-25.
Choose Language Hide Translation Bar
AdditiveRange10
Level III

Creating a function to make multiple graphs at a time

Hello,

I have a question regarding a function to create multiple graphs. So I am making a function which calls the graph builder with certain settings to create multiple graphs. The graphs are similar but do have different amount of columns used and formatting is a bit different. The only input to the function is the datatable with the data.


The function works to create the graphs and I save each one as a variable and then in the end add all of the variables to a list. Later I would like to call each one of the variables (graphs) from the list and place them in different windows. However, that does not work and I get a blank space when calling the list with an index.

 

I tried making the graphs into reports but that renders them noninteractive. 

 

If I call the function in the place where I want to place the graph it will place all 3 graphs at once instead of one at a time.

 

Any help on how to navigate this would be appreciated.

3 REPLIES 3
jthi
Super User

Re: Creating a function to make multiple graphs at a time

You should be able to call the function where you wish to have the graphs at

Names Default To Here(1); 

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

create_plot = function({dt, colname}, {Default Local},
	gb = dt << Graph Builder(
		Variables(X(:age), Y(Eval(colname)), Overlay(:sex)),
		Elements(Points(X, Y, Legend(9)), Line Of Fit(X, Y, Legend(11)))
	);

	return(gb);
);

plots = {};

nw = new window("",
	V List Box(
		Insert Into(plots, create_plot(dt, "height")),
		Insert Into(plots, create_plot(dt, "weight"))
	)
);

If you do not need the list for reference collection, you can just drop it

nw = new window("",
	V List Box(
		gb_height = create_plot(dt, "height"),
		gb_weight = create_plot(dt, "weight")
	)
);

or just

nw = new window("",
	V List Box(
		create_plot(dt, "height"),
		create_plot(dt, "weight")
	)
);

and idea would be similar for multiple windows 

Names Default To Here(1); 

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

create_plot = function({dt, colname}, {Default Local},
	gb = dt << Graph Builder(
		Variables(X(:age), Y(Eval(colname)), Overlay(:sex)),
		Elements(Points(X, Y, Legend(9)), Line Of Fit(X, Y, Legend(11)))
	);

	return(gb);
);

nw = new window("",
	create_plot(dt, "height")
);

nw = new window("",
	create_plot(dt, "weight")
);

Or sometimes you might not need the new window

Names Default To Here(1); 

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

create_plot = function({dt, colname}, {Default Local},
	gb = dt << Graph Builder(
		Variables(X(:age), Y(Eval(colname)), Overlay(:sex)),
		Elements(Points(X, Y, Legend(9)), Line Of Fit(X, Y, Legend(11)))
	);

	return(gb);
);

gb1 = create_plot(dt, "height");
gb2 = create_plot(dt, "weight");

 

-Jarmo
AdditiveRange10
Level III

Re: Creating a function to make multiple graphs at a time

Thanks Jarmo.

 

In the end I did something similar. I made a Match clause and just had the choice of which of the three types of graphs to make and then called the function as many times as I needed with the choice to produce the individual graphs. I think that is equivalent to what you did in the end. I wanted to have all three plots made in the same function since they all have some small differences in formatting, more than just replacing the column name as in your example and I did not want to make 3 different functions for each type which would work as well.

 

 

hogi
Level XII

Re: Creating a function to make multiple graphs at a time

Besides "how to create the graphs?" - one cold also consider the "how to organize the graphs?".
Maybe use a single window and store the graphs as tabs?

Recommended Articles