BookmarkSubscribe
Choose Language Hide Translation Bar
pjkiley
Occasional Contributor

Overlay linear fit of subset of data on top of contour plot of all data

Dear All,

 

I am trying to produce a plot and would appreciate any help I can get.  I feel like what I want to do it pretty simple, but I cannot figure out how to do it through the JMP interface or through scripting.

 

I have a data table with 100 rows, and each row has an X, Y pair that follow a linear relationship.  I also have a third categorical variable labeled "Option".  I can easily produce a contour plot with X and Y axes, and color the contour via the Option column.  I can also easily select only the rows where :Option == "Option 3" and produce a fit to this subset of data.  

 

However, what I cannot seem to do is to produce a contour plot of all the data, with a linear fit of only a subset of data (Option 3) overlayed on the same figure using the same axes.

 

If someone could help me achieve this I would be really grateful.  

 

I have attached the data table as well as a mock-up image of what I wish to achieve. 

 

 

0 Kudos
1 ACCEPTED SOLUTION

Accepted Solutions
Highlighted
julian
Staff

Re: Overlay linear fit of subset of data on top of contour plot of all data

Hi @pjkiley,

It's very difficult to get Graph Builder to plot separate subsets like that, and @dale_lehman's suggestion of Copy Frame Contents is a great way to overlay graph elements from separate plots. But, as you noticed when scripting this gets complicated since those pasted frame contents do not come along.

 

Another option would be to plot all the elements, but then hide (or specifically, make completely transparent) the levels you don't wish to see. That's effectively the same as plotting only the level you do wish to see. Here's a quick gif of how to do that using what I think is the same structure as your data:gb.gif

 

 

and here is the script to reproduce:

 

Open("$SAMPLE_DATA\Big Class.jmp");

Graph Builder(
	Variables( X( :height ), Y( :weight ), Overlay( :sex ), Color( :sex ) ),
	Elements( Contour( X, Y, Overlay( 0 ), Legend( 16 ) ), Line Of Fit( X, Y, Legend( 17 ) ) ),
	SendToReport(
		Dispatch(
			{},
			"400",
			ScaleBox,
			{Legend Model( 17, Properties( 1, {Transparency( 0 )}, Item ID( "M", 1 ) ) )}
		)
	)
);

I didn't show it, but you can also hide the unused elements from your legend by double-clicking, then unchecking the ones you wish to hide:leg.png

I hope this helps get you closer!

@julian 

3 REPLIES 3
dale_lehman
Community Trekker

Re: Overlay linear fit of subset of data on top of contour plot of all data

One way to do this is to create the countour plot in Graph Builder and then exclude all rows except the option you want and create another linear fit graph in Graph Builder. You can copy the frame contents (found under Edit when you right click inside the graph) and then paste the frame contents into the contour graph. This should produce the desired overlay.

pjkiley
Occasional Contributor

Re: Overlay linear fit of subset of data on top of contour plot of all data

Thanks very much for the suggestion.  This does indeed work.  

 

However, I should have mentioned in my previous email that I would like to save this as a script to the data table because I will need to generate this plot several hundred times.  When I save the script after copying the frame contents, the frame contents part does not get saved.  Is there another way to do it?

 

Thanks again,

P


0 Kudos
Highlighted
julian
Staff

Re: Overlay linear fit of subset of data on top of contour plot of all data

Hi @pjkiley,

It's very difficult to get Graph Builder to plot separate subsets like that, and @dale_lehman's suggestion of Copy Frame Contents is a great way to overlay graph elements from separate plots. But, as you noticed when scripting this gets complicated since those pasted frame contents do not come along.

 

Another option would be to plot all the elements, but then hide (or specifically, make completely transparent) the levels you don't wish to see. That's effectively the same as plotting only the level you do wish to see. Here's a quick gif of how to do that using what I think is the same structure as your data:gb.gif

 

 

and here is the script to reproduce:

 

Open("$SAMPLE_DATA\Big Class.jmp");

Graph Builder(
	Variables( X( :height ), Y( :weight ), Overlay( :sex ), Color( :sex ) ),
	Elements( Contour( X, Y, Overlay( 0 ), Legend( 16 ) ), Line Of Fit( X, Y, Legend( 17 ) ) ),
	SendToReport(
		Dispatch(
			{},
			"400",
			ScaleBox,
			{Legend Model( 17, Properties( 1, {Transparency( 0 )}, Item ID( "M", 1 ) ) )}
		)
	)
);

I didn't show it, but you can also hide the unused elements from your legend by double-clicking, then unchecking the ones you wish to hide:leg.png

I hope this helps get you closer!

@julian